]> granicus.if.org Git - graphviz/commitdiff
change behavior of gmalloc in case where user tries to gmalloc 0 bytes
authorellson <devnull@localhost>
Fri, 15 Apr 2005 16:24:25 +0000 (16:24 +0000)
committerellson <devnull@localhost>
Fri, 15 Apr 2005 16:24:25 +0000 (16:24 +0000)
  to a) not attempt the malloc and b) return an invalid pointer (1) so
  that the user will crash when trying to use of free the pointer.

  b) might have been accomplished before, but the malloc was done anyway.

lib/common/utils.c

index 69124ec1a82c4fdec9b9c42b4526339c2c1a0a0a..12639d4ada74a704328719bb422256dd4a052a4f 100644 (file)
@@ -51,9 +51,10 @@ void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
 
 void *gmalloc(size_t nbytes)
 {
-    char *rv = malloc(nbytes);
+    char *rv;
     if (nbytes == 0)
-       return 0;
+       return (char *)1; /* NB Return an invalid pointer - since nobody seems to check for NULL */
+    rv = malloc(nbytes);
     if (rv == NULL) {
        fprintf(stderr, "out of memory\n");
        abort();