]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
common: Cast via uintptr_t rather than unsigned long in UNCONST (#581) master
authorJessica Clarke <jrtc27@jrtc27.com>
Fri, 9 Jan 2026 21:56:25 +0000 (21:56 +0000)
committerGitHub <noreply@github.com>
Fri, 9 Jan 2026 21:56:25 +0000 (21:56 +0000)
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.

src/common.h

index 8aead9c96f6e66f37365eab77db54aa82075f7bc..a2a7abdac75b14b666b0f4062286fcf21d2feb43 100644 (file)
@@ -55,7 +55,7 @@
 #define MAX(a,b)               ((/*CONSTCOND*/(a)>(b))?(a):(b))
 #endif
 
-#define UNCONST(a)             ((void *)(unsigned long)(const void *)(a))
+#define UNCONST(a)             ((void *)(uintptr_t)(const void *)(a))
 #define STRINGIFY(a)           #a
 #define TOSTRING(a)            STRINGIFY(a)
 #define UNUSED(a)              (void)(a)