Skip to content
This repository has been archived by the owner on Mar 15, 2019. It is now read-only.
Permalink
Browse files Browse the repository at this point in the history
Avoid overflowing allocation size in calloc()
  • Loading branch information
xiw committed Apr 14, 2012
1 parent 9333e50 commit 2965eca
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nedmalloc.c
Expand Up @@ -2018,8 +2018,12 @@ NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedpmalloc(nedpool *p, size_t size)
}
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC
{
unsigned flags=NEDMALLOC_FORCERESERVE(p, 0, no*size);
return nedpmalloc2(p, size*no, 0, M2_ZERO_MEMORY|flags);
size_t bytes=no*size;
/* Avoid multiplication overflow. */
if(size && no!=bytes/size)
return 0;
unsigned flags=NEDMALLOC_FORCERESERVE(p, 0, bytes);
return nedpmalloc2(p, bytes, 0, M2_ZERO_MEMORY|flags);
}
NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC
{
Expand Down

0 comments on commit 2965eca

Please sign in to comment.