From patchwork Tue Feb 25 17:35:47 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: 22872 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 AC5F6BF415 for ; Tue, 25 Feb 2025 17:35:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 74BA56872E; Tue, 25 Feb 2025 18:35:54 +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="J7gQFGzC"; dkim-atps=neutral Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8851268729 for ; Tue, 25 Feb 2025 18:35:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1740504952; x=1740764152; bh=xKvIYnd54/uUWp7DK4M4mncZabCWFRWoHU/yRFWVl/w=; h=Date:To:From:Cc: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=J7gQFGzCYGeV44i4dmJQswR+KznjjzJ0mPmJgi8D1Yk4P7jOfLyszjR3hDZUJ+bbX /6L4XOi2CQAQ45axfsUuoP3jxYqa8UxhAbOCJ8A3jRWA9//GhCoUCwSrkW0cRcUVhS g798uXB0xk15kDHT8mvVLm15Qiw0N7zfTX5vFAN5USK0fmhB57/XEAq8ItOiV21RmM eOiBl4LlH/XP1jqcA65z5xcYrpk8duN1ExgHk0ZXtKffp+rzLIwJId3X+1S0ZZmmBC TC4KDTEBTv3hy8Fx/jAr6xXKiWZekri/awu1b+Xzl+YFwVMMA0oj7ldt2iNCTNMWS+ bhO4RwFJsnEXQ== Date: Tue, 25 Feb 2025 17:35:47 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 2/8] libcamera: base: log: Use `std::from_chars()` Message-ID: <20250225173531.2595922-3-pobrn@protonmail.com> In-Reply-To: <20250225173531.2595922-1-pobrn@protonmail.com> References: <20250225173531.2595922-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 05ebc7f672c0c5d53f5040d859b1ce17e687f0cc 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 Reviewed-by: Jacopo Mondi --- 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 009f6c737..42514de97 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); + if (ec != std::errc() || *end != '\0' || severity > LogFatal) severity = LogInvalid; } else { severity = LogInvalid;