]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use uintptr_t for ASan function signatures and macro variables
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 10 Mar 2026 03:20:40 +0000 (20:20 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 10 Mar 2026 23:56:35 +0000 (00:56 +0100)
The ASan runtime ABI expects uptr (pointer-sized unsigned) for both
parameters of __asan_loadN/__asan_storeN. On LLP64 targets like
Windows x64, long is 32-bit while pointers are 64-bit, truncating
size values. Use uintptr_t to match the ABI correctly.

zsanitizer.h

index f57c7b42925c681b8372909e5a62c6f989969976..2c55f9dacf3b677342c061b3ca90fe6345b4edf2 100644 (file)
@@ -31,8 +31,8 @@
  */
 #ifdef Z_ADDRESS_SANITIZER
 #  ifndef __cplusplus
-void __asan_loadN(void *, long);
-void __asan_storeN(void *, long);
+void __asan_loadN(uintptr_t, uintptr_t);
+void __asan_storeN(uintptr_t, uintptr_t);
 #  endif
 #else
 #  define __asan_loadN(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
@@ -46,26 +46,26 @@ void __asan_storeN(void *, long);
 #endif
 
 /* Notify sanitizer runtime about an upcoming read access. */
-#define instrument_read(a, size) do {             \
-    void *__a = (void *)(a);                      \
-    long __size = size;                           \
-    __asan_loadN(__a, __size);                    \
-    __msan_check_mem_is_initialized(__a, __size); \
+#define instrument_read(a, size) do {                     \
+    uintptr_t __a = (uintptr_t)(a);                       \
+    uintptr_t __size = size;                              \
+    __asan_loadN(__a, __size);                            \
+    __msan_check_mem_is_initialized((void *)__a, __size); \
 } while (0)
 
 /* Notify sanitizer runtime about an upcoming write access. */
 #define instrument_write(a, size) do {  \
-    void *__a = (void *)(a);            \
-    long __size = size;                 \
+    uintptr_t __a = (uintptr_t)(a);     \
+    uintptr_t __size = size;            \
     __asan_storeN(__a, __size);         \
 } while (0)
 
 /* Notify sanitizer runtime about an upcoming read/write access. */
-#define instrument_read_write(a, size) do {       \
-    void *__a = (void *)(a);                      \
-    long __size = size;                           \
-    __asan_storeN(__a, __size);                   \
-    __msan_check_mem_is_initialized(__a, __size); \
+#define instrument_read_write(a, size) do {               \
+    uintptr_t __a = (uintptr_t)(a);                       \
+    uintptr_t __size = size;                              \
+    __asan_storeN(__a, __size);                           \
+    __msan_check_mem_is_initialized((void *)__a, __size); \
 } while (0)
 
 #endif