mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-22 14:36:31 +02:00
util/nvmutil: properly handle sizeof in rhex()
sizeof is size_t, so we must act accordingly. casting it to an int is unacceptable. this version is also branchless. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -432,20 +432,20 @@ hextonum(char ch)
|
|||||||
static uint8_t
|
static uint8_t
|
||||||
rhex(void)
|
rhex(void)
|
||||||
{
|
{
|
||||||
static int n = -1;
|
|
||||||
static uint8_t rnum[12];
|
static uint8_t rnum[12];
|
||||||
|
static size_t n = 0;
|
||||||
|
|
||||||
if (n == -1) {
|
if (!n) {
|
||||||
n = sizeof(rnum) - 1;
|
|
||||||
#ifdef HAVE_ARC4RANDOM
|
#ifdef HAVE_ARC4RANDOM
|
||||||
arc4random_buf(rnum, sizeof(rnum));
|
arc4random_buf(rnum, sizeof(rnum));
|
||||||
#else
|
#else
|
||||||
read_file_PERFECTLY_or_die(rfd, rnum, sizeof(rnum),
|
read_file_PERFECTLY_or_die(rfd, rnum, sizeof(rnum),
|
||||||
0, rname, NULL);
|
0, rname, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
n = sizeof(rnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rnum[n--] & 0xf;
|
return rnum[--n] & 0xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user