]> granicus.if.org Git - sudo/commitdiff
Error out on malloc(0); suggested by theo
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 12 Mar 2003 21:23:40 +0000 (21:23 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 12 Mar 2003 21:23:40 +0000 (21:23 +0000)
alloc.c

diff --git a/alloc.c b/alloc.c
index 32d61365420a6823e2e3dec98d535a4ff162eb53..e2f50ff086420e2591ad2215457a89f108853fe8 100644 (file)
--- 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]);