{"id":16986,"url":"https://patchwork.libcamera.org/api/patches/16986/?format=json","web_url":"https://patchwork.libcamera.org/patch/16986/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220805161658.11349-1-laurent.pinchart@ideasonboard.com>","date":"2022-08-05T16:16:58","name":"[libcamera-devel] libcamera: yaml_parser: Return nullopt on error from YamlObject::get()","commit_ref":"1a6c7477fda7c6cfbf3483c529aebf64d7ed6a8e","pull_url":null,"state":"accepted","archived":false,"hash":"f69bc3c3ae781b9133bc9a3069dece2acdbaa4fe","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16986/mbox/","series":[{"id":3377,"url":"https://patchwork.libcamera.org/api/series/3377/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3377","date":"2022-08-05T16:16:58","name":"[libcamera-devel] libcamera: yaml_parser: Return nullopt on error from YamlObject::get()","version":1,"mbox":"https://patchwork.libcamera.org/series/3377/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16986/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16986/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E1196BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Aug 2022 16:17:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42101603F0;\n\tFri,  5 Aug 2022 18:17:10 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2141A603E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Aug 2022 18:17:08 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 81E0D480;\n\tFri,  5 Aug 2022 18:17:07 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659716230;\n\tbh=LUyE4RKzNYB2Z1CosQFaOJ61bHn2Gk3FrltuY8qV25Q=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=10zzgxLpKhTBHAaYrybHwUXdsqsNqxn1Zr2I3WMmCakXMEBvrIoOIQkd+c9lBvmmQ\n\tQC8LalK+B/4PwyUcPRfTms5cT+aCzbqoMSNdoPVaQmuUyDkVLL2p/oG1souYpruzMf\n\tkjaLqQH4YJ3GhC02LR8QY/L9+VqeNNk5/7wzBS6nAN4Re5e2xccHFAORSH8aomsZ30\n\tSi7NYNzF6iItf7ARS8MZFjpcw/yVImDjxRhGaj/wLaPaZmEs+RSQjP5w/F7BOt0/AO\n\t3SyrpRDVMB6yO+kgNtwVR4ZGS2fVSlI8KYXs2hkuAOqFosjFTyITL6NzM8pfSX8XtZ\n\t/ociiUsijZDfA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659716227;\n\tbh=LUyE4RKzNYB2Z1CosQFaOJ61bHn2Gk3FrltuY8qV25Q=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=BXhK/C3+Aym2WVBhMbFTj1dHnaLKnMVRykLuwDIyjOnUeYoxyPVxMLrhvIbw3G0cd\n\tuVEmeRDiHlKTmyE4O5LDyOOr8aT7d64XWfXNdKPxN74dKmALKmyGPR+7aMWwqvxMv/\n\tyGvrnG8ZmAu4Hk6sihLk+uwUJSa1O0eIUl9HUBLI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"BXhK/C3+\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  5 Aug 2022 19:16:58 +0300","Message-Id":"<20220805161658.11349-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] libcamera: yaml_parser: Return nullopt on\n\terror from YamlObject::get()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The YamlParser::get<>() function returns an std::optional<> to indicate\nwhen YAML parsing failed.\n\nThe current implementation returns a default constructed std::optional\nin case of errors with\n\n        return {};\n\nThis has been reported as generating compiler warnings with a gcc 9.3.0\narm64 cross-compiler:\n\n../src/libcamera/yaml_parser.cpp:184:11: error: ‘<anonymous>’ may be used uninitialized in this function [-Werror=maybe-uninitialized]\n  184 |   return {};\n      |           ^\n\nReplace this with an explicit\n\n\treturn std::nullopt;\n\nwhich fixes the warnings and conveys the purpose more explicitly.\n\nReported-by: Christian Rauch <Rauch.Christian@gmx.de>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/yaml_parser.cpp | 48 +++++++++++++++++------------------\n 1 file changed, 24 insertions(+), 24 deletions(-)\n\n\nbase-commit: 26c82ce13697e1af5950f4935ecff83c6453f351","diff":"diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex c96e99e1317c..9162e2250ed4 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -121,24 +121,24 @@ template<>\n std::optional<bool> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"true\")\n \t\treturn true;\n \telse if (value_ == \"false\")\n \t\treturn false;\n \n-\treturn {};\n+\treturn std::nullopt;\n }\n \n template<>\n std::optional<int16_t> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"\")\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tchar *end;\n \n@@ -148,7 +148,7 @@ std::optional<int16_t> YamlObject::get() const\n \tif ('\\0' != *end || errno == ERANGE ||\n \t    value < std::numeric_limits<int16_t>::min() ||\n \t    value > std::numeric_limits<int16_t>::max())\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value;\n }\n@@ -157,10 +157,10 @@ template<>\n std::optional<uint16_t> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"\")\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \t/*\n \t * libyaml parses all scalar values as strings. When a string has\n@@ -171,7 +171,7 @@ std::optional<uint16_t> YamlObject::get() const\n \t */\n \tstd::size_t found = value_.find_first_not_of(\" \\t\");\n \tif (found != std::string::npos && value_[found] == '-')\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tchar *end;\n \n@@ -181,7 +181,7 @@ std::optional<uint16_t> YamlObject::get() const\n \tif ('\\0' != *end || errno == ERANGE ||\n \t    value < std::numeric_limits<uint16_t>::min() ||\n \t    value > std::numeric_limits<uint16_t>::max())\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value;\n }\n@@ -190,10 +190,10 @@ template<>\n std::optional<int32_t> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"\")\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tchar *end;\n \n@@ -203,7 +203,7 @@ std::optional<int32_t> YamlObject::get() const\n \tif ('\\0' != *end || errno == ERANGE ||\n \t    value < std::numeric_limits<int32_t>::min() ||\n \t    value > std::numeric_limits<int32_t>::max())\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value;\n }\n@@ -212,10 +212,10 @@ template<>\n std::optional<uint32_t> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"\")\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \t/*\n \t * libyaml parses all scalar values as strings. When a string has\n@@ -226,7 +226,7 @@ std::optional<uint32_t> YamlObject::get() const\n \t */\n \tstd::size_t found = value_.find_first_not_of(\" \\t\");\n \tif (found != std::string::npos && value_[found] == '-')\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tchar *end;\n \n@@ -236,7 +236,7 @@ std::optional<uint32_t> YamlObject::get() const\n \tif ('\\0' != *end || errno == ERANGE ||\n \t    value < std::numeric_limits<uint32_t>::min() ||\n \t    value > std::numeric_limits<uint32_t>::max())\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value;\n }\n@@ -245,10 +245,10 @@ template<>\n std::optional<double> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (value_ == \"\")\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tchar *end;\n \n@@ -256,7 +256,7 @@ std::optional<double> YamlObject::get() const\n \tdouble value = std::strtod(value_.c_str(), &end);\n \n \tif ('\\0' != *end || errno == ERANGE)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value;\n }\n@@ -265,7 +265,7 @@ template<>\n std::optional<std::string> YamlObject::get() const\n {\n \tif (type_ != Type::Value)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn value_;\n }\n@@ -274,18 +274,18 @@ template<>\n std::optional<Size> YamlObject::get() const\n {\n \tif (type_ != Type::List)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tif (list_.size() != 2)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tauto width = list_[0].value->get<uint32_t>();\n \tif (!width)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \tauto height = list_[1].value->get<uint32_t>();\n \tif (!height)\n-\t\treturn {};\n+\t\treturn std::nullopt;\n \n \treturn Size(*width, *height);\n }\n","prefixes":["libcamera-devel"]}