mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 08:17:31 +02:00
util/nvmutil: use unsigned char in hextonum
char can be signed or unsigned, and this is often implementation-defined. this could result in bad comparisons, so we should specifically cast it. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -512,14 +512,16 @@ set_mac_nib(size_t mac_str_pos, size_t mac_nib_pos)
|
|||||||
static uint8_t
|
static uint8_t
|
||||||
hextonum(char mac_ch)
|
hextonum(char mac_ch)
|
||||||
{
|
{
|
||||||
if ((unsigned)(mac_ch - '0') <= 9)
|
unsigned char ch = (unsigned char)mac_ch;
|
||||||
return mac_ch - '0';
|
|
||||||
|
|
||||||
mac_ch |= 0x20;
|
if ((unsigned)(ch - '0') <= 9)
|
||||||
|
return ch - '0';
|
||||||
|
|
||||||
if ((unsigned)(mac_ch - 'a') <= 5)
|
ch |= 0x20;
|
||||||
return mac_ch - 'a' + 10;
|
|
||||||
else if (mac_ch == '?' || mac_ch == 'x')
|
if ((unsigned)(ch - 'a') <= 5)
|
||||||
|
return ch - 'a' + 10;
|
||||||
|
else if (ch == '?' || ch == 'x')
|
||||||
return rhex(); /* random character */
|
return rhex(); /* random character */
|
||||||
else
|
else
|
||||||
return 16; /* invalid character */
|
return 16; /* invalid character */
|
||||||
|
|||||||
Reference in New Issue
Block a user