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.
This commit is contained in:
Simon Kelley committed 2026-06-02 13:00:18 +01:00
1 parent 4bf46ceb37
commit 2c78b6db6c
1 file changed
+1 -1
+1 -1
View File
@@ -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)
{