libcamera: base: log: Fix uninitialized variable warning
gcc 13.3.0, cross-compiling from amd64 to arm64, warns about a possibly
uninitialized variable in Logger::parseLogLevel():
src/libcamera/base/log.cpp: In static member function ‘static libcamera::LogSeverity libcamera::Logger::parseLogLevel(std::string_view)’:
../../src/libcamera/base/log.cpp:694:55: error: ‘severity’ may be used uninitialized [-Werror=maybe-uninitialized]
694 | if (ec != std::errc() || *end != '\0' || severity > LogFatal)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
src/libcamera/base/log.cpp:690:22: note: ‘severity’ was declared here
690 | unsigned int severity;
| ^~~~~~~~
This appears to be a false positive, as the std::from_chars() function
should set severity value when it returns without an error. Still, the
warning is easy to solve, so fix it by initializing the severity
variable.
Fixes: 8fa119e0b5
("libcamera: base: log: Use `std::from_chars()`")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
c0a58b9798
commit
bb1d216113
1 changed files with 1 additions and 2 deletions
|
@ -687,14 +687,13 @@ LogSeverity Logger::parseLogLevel(std::string_view level)
|
||||||
"FATAL",
|
"FATAL",
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int severity;
|
unsigned int severity = LogInvalid;
|
||||||
|
|
||||||
if (std::isdigit(level[0])) {
|
if (std::isdigit(level[0])) {
|
||||||
auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
|
auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
|
||||||
if (ec != std::errc() || *end != '\0' || severity > LogFatal)
|
if (ec != std::errc() || *end != '\0' || severity > LogFatal)
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
} else {
|
} else {
|
||||||
severity = LogInvalid;
|
|
||||||
for (unsigned int i = 0; i < std::size(names); ++i) {
|
for (unsigned int i = 0; i < std::size(names); ++i) {
|
||||||
if (names[i] == level) {
|
if (names[i] == level) {
|
||||||
severity = i;
|
severity = i;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue