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:
parent
332d8b37ff
commit
455280e5aa
1 changed files with 2 additions and 6 deletions
|
@ -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';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue