[PATCH] libcamera: base: Fix log level parsing when multiple categories are listed
Stefan Klug
stefan.klug at ideasonboard.com
Fri Jun 6 10:37:09 CEST 2025
For a list of log levels like LIBCAMERA_LOG_LEVELS="CatA:0,CatB:1" only
the severity of the last entry is correctly parsed.
Due to the change of level to a string_view in 24c2caa1c1b3 ("libcamera:
base: log: Use `std::string_view` to avoid some copies") the level is no
longer necessarily null terminated as it is a view on the original data.
Replace the check for a terminating null by a check for the end position
to fix the issue.
Fixes: 24c2caa1c1b3 ("libcamera: base: log: Use `std::string_view` to avoid some copies")
Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>
---
src/libcamera/base/log.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 8bf3e1daa9c6..e024b58d7180 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -690,8 +690,9 @@ LogSeverity Logger::parseLogLevel(std::string_view level)
unsigned int severity = LogInvalid;
if (std::isdigit(level[0])) {
- auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
- if (ec != std::errc() || *end != '\0' || severity > LogFatal)
+ const char* levelEnd = level.data() + level.size();
+ auto [end, ec] = std::from_chars(level.data(), levelEnd, severity);
+ if (ec != std::errc() || end != levelEnd || severity > LogFatal)
severity = LogInvalid;
} else {
for (unsigned int i = 0; i < std::size(names); ++i) {
--
2.48.1
More information about the libcamera-devel
mailing list