From 2c2bda31ea4ca66aeec8200f91920d5044f6c45e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 6 Mar 2026 22:08:15 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'util/nvmutil/nvmutil.c') 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 */ -- cgit v1.2.1