From: Ivan Maidanski Date: Thu, 15 Mar 2012 16:30:11 +0000 (+0400) Subject: Fix calloc-related code to prevent SIZE_MAX redefinition in sys headers X-Git-Tag: gc7_3alpha2~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a93f8e5bcad22137f41b6c60a1c7384baaec2b3;p=gc Fix calloc-related code to prevent SIZE_MAX redefinition in sys headers * malloc.c: Include limits.h for SIZE_MAX. * malloc.c (SIZE_MAX, calloc): Define GC_SIZE_MAX instead of SIZE_MAX. --- diff --git a/malloc.c b/malloc.c index 899d6ff1..cb49a5cf 100644 --- a/malloc.c +++ b/malloc.c @@ -374,12 +374,16 @@ void * malloc(size_t lb) } #endif /* GC_LINUX_THREADS */ -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#include +#ifdef SIZE_MAX +# define GC_SIZE_MAX SIZE_MAX +#else +# define GC_SIZE_MAX (~(size_t)0) #endif + void * calloc(size_t n, size_t lb) { - if (lb && n > SIZE_MAX / lb) + if (lb && n > GC_SIZE_MAX / lb) return NULL; # if defined(GC_LINUX_THREADS) /* && !defined(USE_PROC_FOR_LIBRARIES) */ /* libpthread allocated some memory that is only pointed to by */