From 455280e5aa6958266976590aaea42f7b86cef032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Mon, 9 Jun 2025 10:50:54 +0200 Subject: [PATCH] lib: hex: remove unnecessary defensive programming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hex2char() calls in bin2hex() can never fail since buf[i] >> 4 and buf[i] & 0xf always produce values in range 0-15. Signed-off-by: Benjamin Cabé --- lib/utils/hex.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/utils/hex.c b/lib/utils/hex.c index fe4e7351e85..ccbe93ee196 100644 --- a/lib/utils/hex.c +++ b/lib/utils/hex.c @@ -44,12 +44,8 @@ size_t bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen) } for (size_t i = 0; i < buflen; i++) { - if (hex2char(buf[i] >> 4, &hex[2U * i]) < 0) { - return 0; - } - if (hex2char(buf[i] & 0xf, &hex[2U * i + 1U]) < 0) { - return 0; - } + hex2char(buf[i] >> 4, &hex[2U * i]); + hex2char(buf[i] & 0xf, &hex[2U * i + 1U]); } hex[2U * buflen] = '\0';