From 2e77ccbb93a14a0c976bb3ca9d5dbbdc32a12847 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 3 Aug 2022 12:55:39 +0200 Subject: libcamera: yaml_parser: Return nullopt on error The YamlParser::getList<>() function returns an std::optional<> to allow callers to identify cases where parsing the .yaml file failed from cases where the parsed list is just empty. The current implementation returns a default constructed std::optional in case of errors with return {}; The returned value is thus equal to std::nullopt, but the code can be easily misinterpreted as returning an empty vector by a reader. Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- src/libcamera/yaml_parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 84cb57d6..c96e99e1 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -319,7 +319,7 @@ template> YamlObject::getList() const { if (type_ != Type::List) - return {}; + return std::nullopt; std::vector values; values.reserve(list_.size()); @@ -327,7 +327,7 @@ std::optional> YamlObject::getList() const for (const YamlObject &entry : asList()) { const auto value = entry.get(); if (!value) - return {}; + return std::nullopt; values.emplace_back(*value); } -- cgit v1.2.1