[PATCH 50/59] malloc: Use INT_ADD_OVERFLOW instead of __builtin_add_overflow_p

Adhemerval Zanella adhemerval.zanella@linaro.org
Fri Oct 17 19:13:25 GMT 2025


clang does not support the __builtin_*_overflow_p builtins, on gcc
the macros will call __builtin_*_overflow_p.
---
 malloc/malloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 18aa546ec5..f0e53237ee 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -224,6 +224,7 @@
 #include <stdio.h>    /* needed for malloc_stats */
 #include <errno.h>
 #include <assert.h>
+#include <intprops.h>
 
 #include <shlib-compat.h>
 
@@ -3526,8 +3527,8 @@ __libc_free (void *mem)
 #endif
 
   /* Check size >= MINSIZE and p + size does not overflow.  */
-  if (__glibc_unlikely (__builtin_add_overflow_p ((uintptr_t) p, size - MINSIZE,
-						  (uintptr_t) 0)))
+  if (__glibc_unlikely (INT_ADD_OVERFLOW ((uintptr_t) p,
+					  size - MINSIZE)))
     return malloc_printerr_tail ("free(): invalid size");
 
   _int_free_chunk (arena_for_chunk (p), p, size, 0);
-- 
2.43.0



More information about the Libc-alpha mailing list