summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2025-01-21 13:16:20 +0100
committerBarnabás Pőcze <pobrn@protonmail.com>2025-02-27 11:30:23 +0100
commit8fa119e0b50f2b3bf1ce142c5dc642242e56dcd5 (patch)
treed88d09ba635aeec660cd91ae8cd9fbb04afd1c77 /src
parentd40250e03b172ecc5f81299499ea0901f3d5b16d (diff)
libcamera: base: log: Use `std::from_chars()`
Use the `std::from_chars()` function from `<charconv>` to parse the integral log level instead of `strtoul` as it provides an easier to use interface and better type safety. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/base/log.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 009f6c73..42514de9 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -8,6 +8,7 @@
#include <libcamera/base/log.h>
#include <array>
+#include <charconv>
#include <fnmatch.h>
#include <fstream>
#include <iostream>
@@ -686,12 +687,11 @@ LogSeverity Logger::parseLogLevel(const std::string &level)
"FATAL",
};
- int severity;
+ unsigned int severity;
if (std::isdigit(level[0])) {
- char *endptr;
- severity = strtoul(level.c_str(), &endptr, 10);
- if (*endptr != '\0' || severity > LogFatal)
+ auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
+ if (ec != std::errc() || *end != '\0' || severity > LogFatal)
severity = LogInvalid;
} else {
severity = LogInvalid;