summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-14 19:13:12 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-14 19:13:38 +0000
commit58a80f8c3fd5dffa6a578572000e7aa9a1b6a593 (patch)
tree864cf66f3cbc2d4c63d1807036eac3f3196b7ad9
parentfeb4db34a25cdbee2ea4ea7896bdede7e82273ba (diff)
util/nvmutil: even safer pointer comparison
we assert now that ulong is the size of a pointer, therefore we know that it can fit a pointer reliably. this code is written for c90 spec so lacks uintptr Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index c8b8060b..90b96bc6 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -246,6 +246,9 @@ typedef char static_assert_int_ge_32[(sizeof(int) >= 4) ? 1 : -1];
typedef char static_assert_twos_complement[
((-1 & 3) == 3) ? 1 : -1
];
+typedef char assert_ulong_ptr[
+ (sizeof(ulong) >= sizeof(void *)) ? 1 : -1
+];
/*
* We set _FILE_OFFSET_BITS 64, but we only handle
@@ -1801,15 +1804,15 @@ static ssize_t
rw_gbe_file_exact(int fd, u8 *mem, size_t nrw,
off_t off, int rw_type)
{
- size_t mem_addr;
- size_t buf_addr;
- size_t buf_end;
+ ulong mem_addr;
+ ulong buf_addr;
+ ulong buf_end;
if (mem == NULL)
goto err_rw_gbe_file_exact;
- mem_addr = (size_t)(void *)mem;
- buf_addr = (size_t)(void *)buf;
+ mem_addr = (ulong)(void *)mem;
+ buf_addr = (ulong)(void *)buf;
buf_end = buf_addr + GBE_FILE_SIZE;
if (mem != (void *)pad &&