diff options
Diffstat (limited to 'usr/src/lib/libmalloc/common/malloc.c')
-rw-r--r-- | usr/src/lib/libmalloc/common/malloc.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/usr/src/lib/libmalloc/common/malloc.c b/usr/src/lib/libmalloc/common/malloc.c index 1d2bbef56b..25343ea62c 100644 --- a/usr/src/lib/libmalloc/common/malloc.c +++ b/usr/src/lib/libmalloc/common/malloc.c @@ -27,8 +27,6 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #ifndef debug @@ -37,6 +35,7 @@ #include <stdlib.h> #include <string.h> +#include <errno.h> #include "assert.h" #include "malloc.h" #include "mallint.h" @@ -845,12 +844,24 @@ void * calloc(size_t num, size_t size) { char *mp; + size_t total; + + if (num == 0 || size == 0) { + total = 0; + } else { + total = num * size; + + /* check for overflow */ + if ((total / num) != size) { + errno = ENOMEM; + return (NULL); + } + } - num *= size; - mp = malloc(num); + mp = malloc(total); if (mp == NULL) return (NULL); - (void) memset(mp, 0, num); + (void) memset(mp, 0, total); return (mp); } |