Skip to content

Commit 2c1db04

Browse files
authored
common: Cast via uintptr_t rather than unsigned long in UNCONST (#581)
On ILP32 and LP64 systems, unsigned long is sufficient to round-trip pointers, but on LLP64 systems it is too small, and on systems like CHERI where pointers are capabilities, it does not propagate capability metadata, and casting back to a pointer to yield a pointer that cannot be dereferenced. Instead, cast via uintptr_t to ensure we always use an integral type that can losslessly round-trip pointers.
1 parent cd0b269 commit 2c1db04

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
5656
#endif
5757

58-
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
58+
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
5959
#define STRINGIFY(a) #a
6060
#define TOSTRING(a) STRINGIFY(a)
6161
#define UNUSED(a) (void)(a)

0 commit comments

Comments
 (0)