Don't assume realloc() can handle NULL pointers (backport from trunk)
authorPeter Maydell <pmaydell@chiark.greenend.org.uk>
Wed, 21 May 2008 18:07:29 +0000 (18:07 +0000)
committerPeter Maydell <pmaydell@chiark.greenend.org.uk>
Wed, 21 May 2008 18:07:29 +0000 (18:07 +0000)
ChangeLog
sbr/utils.c

index e9d73d3..507c457 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-05-21  Peter Maydell  <pmaydell@chiark.greenend.org.uk>
 
+       * sbr/utils.c (mh_xrealloc): don't assume realloc() can
+       handle NULL pointers; some non-POSIX realloc()s can't.
+       (Ported from trunk.)
+
        * sbr/dtimep.lex: add some table size declarations for the
        benefit of elderly lexes with small defaults. (Ported from
        trunk.)
index d822995..7c4ddcf 100644 (file)
@@ -47,6 +47,10 @@ mh_xrealloc(void *ptr, size_t size)
 {
     void *memory;
 
+    /* Some non-POSIX realloc()s don't cope with realloc(NULL,sz) */
+    if (!ptr)
+        return mh_xmalloc(size);
+
     if (size == 0)
         adios(NULL, "Tried to realloc 0bytes");