From patchwork Tue Oct 28 18:29:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 24869 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 31FD6C3259 for ; Tue, 28 Oct 2025 18:29:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5249E6080D; Tue, 28 Oct 2025 19:29:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KHmZQI3G"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DDC25606DE for ; Tue, 28 Oct 2025 19:29:42 +0100 (CET) Received: from charm.hippo-penny.ts.net (unknown [209.38.108.23]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B7CD413BE; Tue, 28 Oct 2025 19:27:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761676073; bh=0bjppOVfhW4ORN8ppW0OK8emUmuaUUQV+umwtwQGjM0=; h=From:To:Cc:Subject:Date:From; b=KHmZQI3GickMRx7CTmXqOuPUJlhbAApPeDfgxlJaJfDUp8W/aYAbObwfwutr4BqGh +sh+xxiQQ7CRlutIxKqJpHMPKCkmjmZCPGj+FtPUYKqfRHovIVug8UmfPbyzMYvGHK izQocHhgWO3vIIZVKLdVO0AQ6yRhLo7rYNibNe9U= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH] libcamera: base: utils: Prevent hex signed extension Date: Tue, 28 Oct 2025 18:29:36 +0000 Message-ID: <20251028182936.14362-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.51.0 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" When converting signed values to hex strings using the utils::hex helpers, signed negative values get sign extended to the larger 64 bit type. This causes values such as 0x80 to be printed as 0xffffffffffffff80 instead. Resolve this by first converting all signed integer types to an unsigned type of the same size before extending to the larger type. Signed-off-by: Kieran Bingham --- include/libcamera/base/utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index cb8caaa9bacc..fdc3fd91f1b6 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -95,7 +95,7 @@ _hex hex(T value, unsigned int width = 0); template<> inline _hex hex(int8_t value, unsigned int width) { - return { static_cast(value), width ? width : 2 }; + return { static_cast(static_cast(value)), width ? width : 2 }; } template<> @@ -107,7 +107,7 @@ inline _hex hex(uint8_t value, unsigned int width) template<> inline _hex hex(int16_t value, unsigned int width) { - return { static_cast(value), width ? width : 4 }; + return { static_cast(static_cast(value)), width ? width : 4 }; } template<> @@ -119,7 +119,7 @@ inline _hex hex(uint16_t value, unsigned int width) template<> inline _hex hex(int32_t value, unsigned int width) { - return { static_cast(value), width ? width : 8 }; + return { static_cast(static_cast(value)), width ? width : 8 }; } template<>