From 2c78b6db6cc4da9db6d6bab7e4d1e62d90a295c3 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Tue, 2 Jun 2026 13:00:18 +0100 Subject: [PATCH] Better code to make human-friendly tokens for pointers in log-malloc. It turns out that subtracting NULL from a pointer to turn it into an integer is not a good idea, because subtracting a NULL pointer is undefined behaviour in C. The correct way to do this is simply to cast the pointer to uintptr_t. The only fly in this ointment is that the C standard does not mandate support for uintptr_t. In practice, I doubt anyone is running dnsmasq on the long-dead architectures where this might be a problem. Thanks to Matthias Andree for the heads-up. --- src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index 3d8ed40..fbed5f8 100644 --- a/src/util.c +++ b/src/util.c @@ -947,7 +947,7 @@ int kernel_version(void) } #endif -#define hash_ptr(x) (((unsigned int)(((char *)(x)) - ((char *)NULL))) & 0xffffff) +#define hash_ptr(x) (((uintptr_t)(x)) & 0xffffff) void *whine_malloc_real(const char *func, unsigned int line, size_t size) {