From patchwork Mon Feb 17 18:54:45 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: 22802 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 B9A8EC3200 for ; Mon, 17 Feb 2025 18:54:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7286668686; Mon, 17 Feb 2025 19:54:51 +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="erP1GLnY"; dkim-atps=neutral Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A4D56867F for ; Mon, 17 Feb 2025 19:54:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1739818489; x=1740077689; bh=PYr8O0x9BteBWkfQs3r5XTedGHlewmyEL4aOauG2Ju8=; 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=erP1GLnYqknhVZHG4cm+Asok0Pvzzf1U+5l5Tt/4EoGMC7GEO1DNaT2EtSi6cHWUf JF2VDnHDHgVZgdUPlvSHzx/2gJJm6aqua4oNt3rHbbP1FheBPI2hAzTFYuzczOZFiB 8yV4sO4tgZascan6QPn9HOWiNGpOylFXgiPkPZAeENUCFgr8yGPKiTLU/pBMWp7+io yRRQ6j56SQE0Q4i2tlxZBVat5/tkWYcj3R8B3PRqhPx3O7y5J6fp1oK7p5d83bDG+q FI5a1AXg+3AU8s9Bhn6JKTdAXSVhEgjsnndSie9Piq/XWA5AThiPSI3ai+UskWwFZi /uWd00soay1nA== Date: Mon, 17 Feb 2025 18:54:45 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 2/8] libcamera: base: log: Use `std::from_chars()` Message-ID: <20250217185433.306833-3-pobrn@protonmail.com> In-Reply-To: <20250217185433.306833-1-pobrn@protonmail.com> References: <20250217185433.306833-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: a9381b72093bdc970382c6f3f22dfb8228ea5d5f 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 8c72a005d..3dea1e178 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;