Skip to content

Commit 455280e

Browse files
kartbendkalowsk
authored andcommitted
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>
1 parent 332d8b3 commit 455280e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

lib/utils/hex.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ size_t bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen)
4444
}
4545

4646
for (size_t i = 0; i < buflen; i++) {
47-
if (hex2char(buf[i] >> 4, &hex[2U * i]) < 0) {
48-
return 0;
49-
}
50-
if (hex2char(buf[i] & 0xf, &hex[2U * i + 1U]) < 0) {
51-
return 0;
52-
}
47+
hex2char(buf[i] >> 4, &hex[2U * i]);
48+
hex2char(buf[i] & 0xf, &hex[2U * i + 1U]);
5349
}
5450

5551
hex[2U * buflen] = '\0';

0 commit comments

Comments
 (0)