mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
util/nvmutil: tidy up hextonum
i had a bunch of hacks in here because i was previously using very buggy rand. now it's ok. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -33,44 +33,20 @@ hextonum(char ch_s)
|
|||||||
|
|
||||||
ch = (unsigned char)ch_s;
|
ch = (unsigned char)ch_s;
|
||||||
|
|
||||||
if ((unsigned int)(ch - '0') <= 9) {
|
if ((unsigned int)(ch - '0') <= 9)
|
||||||
|
return ch - '0';
|
||||||
rval = ch - '0';
|
|
||||||
goto hextonum_success;
|
|
||||||
}
|
|
||||||
|
|
||||||
ch |= 0x20;
|
ch |= 0x20;
|
||||||
|
|
||||||
if ((unsigned int)(ch - 'a') <= 5) {
|
if ((unsigned int)(ch - 'a') <= 5)
|
||||||
|
return ch - 'a' + 10;
|
||||||
rval = ch - 'a' + 10;
|
|
||||||
goto hextonum_success;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ch == '?' || ch == 'x') {
|
if (ch == '?' || ch == 'x') {
|
||||||
|
|
||||||
rset(&rval, sizeof(rval));
|
rset(&rval, sizeof(rval));
|
||||||
|
return rval & 0xf;
|
||||||
goto hextonum_success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
goto err_hextonum;
|
return 16;
|
||||||
|
|
||||||
hextonum_success:
|
|
||||||
|
|
||||||
errno = saved_errno;
|
|
||||||
return (unsigned short)rval & 0xf;
|
|
||||||
|
|
||||||
err_hextonum:
|
|
||||||
|
|
||||||
if (errno == saved_errno)
|
|
||||||
errno = EINVAL;
|
|
||||||
else
|
|
||||||
return 17; /* 17 indicates getrandom/urandom fail */
|
|
||||||
|
|
||||||
return 16; /* invalid character */
|
|
||||||
|
|
||||||
/* caller just checks >15. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user