]> granicus.if.org Git - nethack/commitdiff
another re_alloc() bit
authorPatR <rankin@nethack.org>
Tue, 31 May 2022 17:36:12 +0000 (10:36 -0700)
committerPatR <rankin@nethack.org>
Tue, 31 May 2022 17:36:12 +0000 (10:36 -0700)
realloc(NULL, size) is legitimate usage and nhrealloc() shouldn't
log a "<  0x00000000 __FILE__ __LINE__" entry for it.  heaputil
would complain about freeing Null.

src/alloc.c

index 244dc2cb8be097f15e11c158a09b631da61b8d48..8113a9389162ca3937e39d7c5ab3a3bf2e8cccbd 100644 (file)
@@ -164,9 +164,10 @@ nhrealloc(
                         * allocation rather than make a new one */
 
         if (newptr != oldptr) {
-            /* realloc() freed oldptr */
-            (void) fprintf(heaplog, "%c%5s %s %4d %s\n", '<', "",
-                           fmt_ptr((genericptr_t) oldptr), line, file);
+            /* if oldptr wasn't Null, realloc() freed it */
+            if (oldptr)
+                (void) fprintf(heaplog, "%c%5s %s %4d %s\n", '<', "",
+                               fmt_ptr((genericptr_t) oldptr), line, file);
             op = '>'; /* new allocation rather than size-change of old one */
         }
         (void) fprintf(heaplog, "%c%5u %s %4d %s\n", op, newlth,