Change our malloc routines to return NULL when the argument is 0.
authorellson <devnull@localhost>
Tue, 18 Oct 2005 21:06:26 +0000 (21:06 +0000)
committerellson <devnull@localhost>
Tue, 18 Oct 2005 21:06:26 +0000 (21:06 +0000)
lib/common/memory.c

index a1d24f40e4cbbb30635d4f5f60a6476dd16cbe8b..8713081d535e8ddcc1f86cfebacbe16feae3de32 100644 (file)
 
 void *zmalloc(size_t nbytes)
 {
-    char *rv = malloc(nbytes);
+    char *rv;
     if (nbytes == 0)
        return 0;
-    if (rv == NULL) {
-       fprintf(stderr, "out of memory\n");
-       abort();
-    }
+    rv = gmalloc(nbytes);
     memset(rv, 0, nbytes);
     return rv;
 }
@@ -51,7 +48,7 @@ void *gmalloc(size_t nbytes)
 {
     char *rv;
     if (nbytes == 0)
-       return (char *)1; /* NB Return an invalid pointer - since nobody seems to check for NULL */
+       return NULL;
     rv = malloc(nbytes);
     if (rv == NULL) {
        fprintf(stderr, "out of memory\n");