mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-12 23:09:45 +03:00
libcamera: base: Fix log level parsing when multiple categories are
listed 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 in24c2caa1c1
("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:24c2caa1c1
("libcamera: base: log: Use `std::string_view` to avoid some copies") Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
8ea3ef083f
commit
0dfb052fbd
2 changed files with 4 additions and 3 deletions
|
@ -690,8 +690,9 @@ LogSeverity Logger::parseLogLevel(std::string_view level)
|
||||||
unsigned int severity = LogInvalid;
|
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);
|
const char *levelEnd = level.data() + level.size();
|
||||||
if (ec != std::errc() || *end != '\0' || severity > LogFatal)
|
auto [end, ec] = std::from_chars(level.data(), levelEnd, severity);
|
||||||
|
if (ec != std::errc() || end != levelEnd || severity > LogFatal)
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
} else {
|
} else {
|
||||||
for (unsigned int i = 0; i < std::size(names); ++i) {
|
for (unsigned int i = 0; i < std::size(names); ++i) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
log_test = [
|
log_test = [
|
||||||
{'name': 'log_api', 'sources': ['log_api.cpp'], 'should_fail': true},
|
{'name': 'log_api', 'sources': ['log_api.cpp']},
|
||||||
{'name': 'log_process', 'sources': ['log_process.cpp']},
|
{'name': 'log_process', 'sources': ['log_process.cpp']},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue