lib: hex: remove unnecessary defensive programming

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é <benjamin@zephyrproject.org>
This commit is contained in:
Benjamin Cabé 2025-06-09 10:50:54 +02:00 committed by Dan Kalowsky
commit 455280e5aa

View file

@ -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';