From: Peter Maydell Date: Wed, 21 May 2008 18:05:49 +0000 (+0000) Subject: Don't rely on realloc() to follow POSIX in handling a NULL pointer X-Git-Tag: PRE_POSIX_CONVERSION~60 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=b84d8f3a2a435ecad9b75900a9f31445fb71e187;p=mmh Don't rely on realloc() to follow POSIX in handling a NULL pointer --- diff --git a/ChangeLog b/ChangeLog index 8da5111..a3eff81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2008-05-21 Peter Maydell + * sbr/utils.c (mh_xrealloc): don't assume realloc() can + handle NULL pointers; some non-POSIX realloc()s can't. + * sbr/dtimep.lex: add some table size declarations for the benefit of elderly lexes with small defaults. diff --git a/sbr/utils.c b/sbr/utils.c index d822995..7c4ddcf 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -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");