From: Todd C. Miller Date: Wed, 12 Mar 2003 21:23:40 +0000 (+0000) Subject: Error out on malloc(0); suggested by theo X-Git-Tag: SUDO_1_6_7~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e041c3f35d9cabca3a6959f9547c2a8cdba5e85;p=sudo Error out on malloc(0); suggested by theo --- diff --git a/alloc.c b/alloc.c index 32d613654..e2f50ff08 100644 --- a/alloc.c +++ b/alloc.c @@ -74,6 +74,11 @@ emalloc(size) { VOID *ptr; + if (size == 0) { + (void) fprintf(stderr, "%s: internal error, tried to malloc(0)\n", + Argv[0]); + exit(1); + } if ((ptr = (VOID *) malloc(size)) == NULL) { (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); exit(1); @@ -92,6 +97,11 @@ erealloc(ptr, size) size_t size; { + if (size == 0) { + (void) fprintf(stderr, "%s: internal error, tried to realloc(0)\n", + Argv[0]); + exit(1); + } ptr = ptr ? (VOID *) realloc(ptr, size) : (VOID *) malloc(size); if (ptr == NULL) { (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);