From 67fd7d720b4845a22d3e97009212d20cd22df83d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 28 Jan 2026 18:06:02 +0200 Subject: [PATCH] libcamera: yaml_parser: Fix uninitialized variable warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc 14.3.0, cross-compiling from amd64 to arm64, warns about a possibly uninitialized variable in YamlObject::Getter<>::get(): In file included from ../../include/libcamera/internal/yaml_parser.h:12, from ../../src/libcamera/yaml_parser.cpp:8: In constructor ‘constexpr std::_Optional_payload_base<_Tp>::_Storage<_Up, >::_Storage(std::in_place_t, _Args&& ...) [with _Args = {unsigned char}; _Up = unsigned char; bool = true; _Tp = unsigned char]’, inlined from ‘constexpr std::_Optional_payload_base<_Tp>::_Optional_payload_base(std::in_place_t, _Args&& ...) [with _Args = {unsigned char}; _Tp = unsigned char]’ at include/c++/14.3.0/optional:122:4, inlined from ‘constexpr std::_Optional_payload::_Optional_payload(std::in_place_t, _Args&& ...) [with _Args = {unsigned char}][inherited from std::_Optional_payload_base]’ at include/c++/14.3.0/optional:337:42, inlined from ‘constexpr std::_Optional_base<_Tp, true, true>::_Optional_base(std::in_place_t, _Args&& ...) [with _Args = {unsigned char}; typename std::enable_if, bool>::type = false; _Tp = unsigned char]’ at include/c++/14.3.0/optional:648:4, inlined from ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = unsigned char; typename std::enable_if<__and_v, typename std::remove_cv::type>::type> >, std::__not_::type>::type> >, std::is_constructible<_T1, _U1>, std::is_convertible<_Iter, _Iterator> >, bool>::type = true; _Tp = unsigned char]’ at include/c++/14.3.0/optional:747:47, inlined from ‘std::optional<_Tp> libcamera::YamlObject::Getter || is_same_v) || is_same_v) || is_same_v) || is_same_v) || is_same_v), void>::type>::get(const libcamera::YamlObject&) const [with T = unsigned char]’ at ../../src/libcamera/yaml_parser.cpp:172:10: include/c++/14.3.0/optional:210:15: error: ‘value’ may be used uninitialized [-Werror=maybe-uninitialized] 210 | : _M_value(std::forward<_Args>(__args)...) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/libcamera/yaml_parser.cpp: In member function ‘std::optional<_Tp> libcamera::YamlObject::Getter || is_same_v) || is_same_v) || is_same_v) || is_same_v) || is_same_v), void>::type>::get(const libcamera::YamlObject&) const [with T = unsigned char]’: ../../src/libcamera/yaml_parser.cpp:165:19: note: ‘value’ was declared here 165 | T value; | ^~~~~ This appears to be a false positive, as the std::from_chars() function should set value when it returns without an error. Commit bb1d216113bc ("libcamera: base: log: Fix uninitialized variable warning") fixed a similar warning with gcc 13.3.0. The warning is easy to work around by initializing the variable, and doing so shouldn't be too costly as the type T is restricted to being an integer. Fix the build by doing so. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Barnabás Pőcze --- src/libcamera/yaml_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index a5e42461..e13b5fae 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -162,7 +162,7 @@ struct YamlObject::Getter