From patchwork Tue Jan 21 18:50:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22603 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ED7A4BD16B for ; Tue, 21 Jan 2025 18:51:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3F836855D; Tue, 21 Jan 2025 19:51:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="DR5nmybS"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F9FD60380 for ; Tue, 21 Jan 2025 19:51:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1737485461; x=1737744661; bh=pzEZ4IbBHAq23BnuKGlTxXSMQlmVd18qIypC2hErXjI=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=DR5nmybSCJq70EKEuhtRksOvSB/U02N8s0x3Lo8bm/jrjsHdHRb5YrpOzeKdQ2Igm Aw4JoNX/Akxj/AcFnfkyHE0G+bXcu8/L76DZQ+8Ezobob5i76HGCumZ5bFp/d/Ffep P0zoYAtl4cSHrwJChF8qmAeEY7t1kF2WEnknQSvba+1ZkfOVdUdFpBuqJ4KOLVAVCe PJgZdrOg2xwSaluOr217Cz45O5DXvPKFqlCBKnu6mYmG1x9fs1KcX7vtoaPNtuDZzW fYVpLBZ+3XdVPBheBoXjyLgmwPTTe0tMbZ+PDM0OjRytWLq3MRmvySXxviTqA1CmlN OCwFmEGbAzQbA== Date: Tue, 21 Jan 2025 18:50:58 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 2/7] libcamera: base: log: Use `std::from_chars()` Message-ID: <20250121185044.300816-3-pobrn@protonmail.com> In-Reply-To: <20250121185044.300816-1-pobrn@protonmail.com> References: <20250121185044.300816-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 6031d72237e92d7b78308b19f636b7f4ce7ea943 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the `std::from_chars()` function from `` 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 Reviewed-by: Laurent Pinchart --- src/libcamera/base/log.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 61a43d525..1024fed7f 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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, 10); + if (ec != std::errc() || *end != '\0' || severity > LogFatal) severity = LogInvalid; } else { severity = LogInvalid;