From patchwork Fri Aug 5 16:16:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16986 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E1196BE173 for ; Fri, 5 Aug 2022 16:17:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42101603F0; Fri, 5 Aug 2022 18:17:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659716230; bh=LUyE4RKzNYB2Z1CosQFaOJ61bHn2Gk3FrltuY8qV25Q=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=10zzgxLpKhTBHAaYrybHwUXdsqsNqxn1Zr2I3WMmCakXMEBvrIoOIQkd+c9lBvmmQ QC8LalK+B/4PwyUcPRfTms5cT+aCzbqoMSNdoPVaQmuUyDkVLL2p/oG1souYpruzMf kjaLqQH4YJ3GhC02LR8QY/L9+VqeNNk5/7wzBS6nAN4Re5e2xccHFAORSH8aomsZ30 Si7NYNzF6iItf7ARS8MZFjpcw/yVImDjxRhGaj/wLaPaZmEs+RSQjP5w/F7BOt0/AO 3SyrpRDVMB6yO+kgNtwVR4ZGS2fVSlI8KYXs2hkuAOqFosjFTyITL6NzM8pfSX8XtZ /ociiUsijZDfA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2141A603E4 for ; Fri, 5 Aug 2022 18:17:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BXhK/C3+"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 81E0D480; Fri, 5 Aug 2022 18:17:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659716227; bh=LUyE4RKzNYB2Z1CosQFaOJ61bHn2Gk3FrltuY8qV25Q=; h=From:To:Cc:Subject:Date:From; b=BXhK/C3+Aym2WVBhMbFTj1dHnaLKnMVRykLuwDIyjOnUeYoxyPVxMLrhvIbw3G0cd uVEmeRDiHlKTmyE4O5LDyOOr8aT7d64XWfXNdKPxN74dKmALKmyGPR+7aMWwqvxMv/ yGvrnG8ZmAu4Hk6sihLk+uwUJSa1O0eIUl9HUBLI= 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 Subject: [libcamera-devel] [PATCH] libcamera: yaml_parser: Return nullopt on error from YamlObject::get() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The YamlParser::get<>() function returns an std::optional<> to indicate when YAML parsing failed. The current implementation returns a default constructed std::optional in case of errors with return {}; This has been reported as generating compiler warnings with a gcc 9.3.0 arm64 cross-compiler: ../src/libcamera/yaml_parser.cpp:184:11: error: ‘’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 184 | return {}; | ^ Replace this with an explicit return std::nullopt; which fixes the warnings and conveys the purpose more explicitly. Reported-by: Christian Rauch Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain --- src/libcamera/yaml_parser.cpp | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) base-commit: 26c82ce13697e1af5950f4935ecff83c6453f351 diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index c96e99e1317c..9162e2250ed4 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -121,24 +121,24 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "true") return true; else if (value_ == "false") return false; - return {}; + return std::nullopt; } template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "") - return {}; + return std::nullopt; char *end; @@ -148,7 +148,7 @@ std::optional YamlObject::get() const if ('\0' != *end || errno == ERANGE || value < std::numeric_limits::min() || value > std::numeric_limits::max()) - return {}; + return std::nullopt; return value; } @@ -157,10 +157,10 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "") - return {}; + return std::nullopt; /* * libyaml parses all scalar values as strings. When a string has @@ -171,7 +171,7 @@ std::optional YamlObject::get() const */ std::size_t found = value_.find_first_not_of(" \t"); if (found != std::string::npos && value_[found] == '-') - return {}; + return std::nullopt; char *end; @@ -181,7 +181,7 @@ std::optional YamlObject::get() const if ('\0' != *end || errno == ERANGE || value < std::numeric_limits::min() || value > std::numeric_limits::max()) - return {}; + return std::nullopt; return value; } @@ -190,10 +190,10 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "") - return {}; + return std::nullopt; char *end; @@ -203,7 +203,7 @@ std::optional YamlObject::get() const if ('\0' != *end || errno == ERANGE || value < std::numeric_limits::min() || value > std::numeric_limits::max()) - return {}; + return std::nullopt; return value; } @@ -212,10 +212,10 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "") - return {}; + return std::nullopt; /* * libyaml parses all scalar values as strings. When a string has @@ -226,7 +226,7 @@ std::optional YamlObject::get() const */ std::size_t found = value_.find_first_not_of(" \t"); if (found != std::string::npos && value_[found] == '-') - return {}; + return std::nullopt; char *end; @@ -236,7 +236,7 @@ std::optional YamlObject::get() const if ('\0' != *end || errno == ERANGE || value < std::numeric_limits::min() || value > std::numeric_limits::max()) - return {}; + return std::nullopt; return value; } @@ -245,10 +245,10 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; if (value_ == "") - return {}; + return std::nullopt; char *end; @@ -256,7 +256,7 @@ std::optional YamlObject::get() const double value = std::strtod(value_.c_str(), &end); if ('\0' != *end || errno == ERANGE) - return {}; + return std::nullopt; return value; } @@ -265,7 +265,7 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::Value) - return {}; + return std::nullopt; return value_; } @@ -274,18 +274,18 @@ template<> std::optional YamlObject::get() const { if (type_ != Type::List) - return {}; + return std::nullopt; if (list_.size() != 2) - return {}; + return std::nullopt; auto width = list_[0].value->get(); if (!width) - return {}; + return std::nullopt; auto height = list_[1].value->get(); if (!height) - return {}; + return std::nullopt; return Size(*width, *height); }