diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-06 22:08:15 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-06 22:09:56 +0000 |
| commit | 2c2bda31ea4ca66aeec8200f91920d5044f6c45e (patch) | |
| tree | 36056f77c37acd815ead923e335490632b5a0953 /util/nvmutil | |
| parent | f57358ac1eec2229da2f97e978a747a5458dfd4c (diff) | |
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>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 1e918516..513ed80e 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -512,14 +512,16 @@ set_mac_nib(size_t mac_str_pos, size_t mac_nib_pos) static uint8_t hextonum(char mac_ch) { - if ((unsigned)(mac_ch - '0') <= 9) - return mac_ch - '0'; + unsigned char ch = (unsigned char)mac_ch; - mac_ch |= 0x20; + if ((unsigned)(ch - '0') <= 9) + return ch - '0'; - if ((unsigned)(mac_ch - 'a') <= 5) - return mac_ch - 'a' + 10; - else if (mac_ch == '?' || mac_ch == 'x') + ch |= 0x20; + + if ((unsigned)(ch - 'a') <= 5) + return ch - 'a' + 10; + else if (ch == '?' || ch == 'x') return rhex(); /* random character */ else return 16; /* invalid character */ |
