Skip to content
Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivmai committed Mar 15, 2012
1 parent 5a64ce4 commit 6a93f8e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions malloc.c
Expand Up @@ -374,12 +374,16 @@ void * malloc(size_t lb)
}
#endif /* GC_LINUX_THREADS */

#ifndef SIZE_MAX
#define SIZE_MAX (~(size_t)0)
#include <limits.h>
#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 */
Expand Down

0 comments on commit 6a93f8e

Please sign in to comment.