diff options
Diffstat (limited to 'util/libreboot-utils/lib/num.c')
| -rw-r--r-- | util/libreboot-utils/lib/num.c | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index 79d6b409..66fc26f1 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -33,50 +33,24 @@ hextonum(char ch_s) ch = (unsigned char)ch_s; - if ((unsigned int)(ch - '0') <= 9) { - - rval = ch - '0'; - goto hextonum_success; - } + if ((unsigned int)(ch - '0') <= 9) + return ch - '0'; ch |= 0x20; - if ((unsigned int)(ch - 'a') <= 5) { - - rval = ch - 'a' + 10; - goto hextonum_success; - } - - if (ch == '?' || ch == 'x') { - - rset(&rval, sizeof(rval)); - - goto hextonum_success; - } - - goto err_hextonum; - -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 */ + if ((unsigned int)(ch - 'a') <= 5) + return ch - 'a' + 10; - return 16; /* invalid character */ + if (ch == '?' || ch == 'x') + return rsize(16); /* <-- with rejection sampling! */ - /* caller just checks >15. */ + return 16; } void check_bin(size_t a, const char *a_name) { if (a > 1) - err_no_cleanup(0, EINVAL, "%s must be 0 or 1, but is %lu", + err_exit(EINVAL, "%s must be 0 or 1, but is %lu", a_name, (size_t)a); } |
