summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-06 14:44:44 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-06 14:53:36 +0000
commita4b9a333a94b2786f9d79102e21c77e509b31145 (patch)
tree2611751ee386cb5cda304ea3d6dd816f5c60d463 /util/nvmutil
parentcc47a756f2bd2569e1f1fdceb3f2cb2b49591586 (diff)
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>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index c5510e8f..5f126dd4 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -432,20 +432,20 @@ hextonum(char ch)
static uint8_t
rhex(void)
{
- static int n = -1;
static uint8_t rnum[12];
+ static size_t n = 0;
- if (n == -1) {
- n = sizeof(rnum) - 1;
+ if (!n) {
#ifdef HAVE_ARC4RANDOM
arc4random_buf(rnum, sizeof(rnum));
#else
read_file_PERFECTLY_or_die(rfd, rnum, sizeof(rnum),
0, rname, NULL);
#endif
+ n = sizeof(rnum);
}
- return rnum[n--] & 0xf;
+ return rnum[--n] & 0xf;
}
static void