]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport tim_one's checkin of
authorMichael W. Hudson <mwh@python.net>
Tue, 5 Mar 2002 14:23:56 +0000 (14:23 +0000)
committerMichael W. Hudson <mwh@python.net>
Tue, 5 Mar 2002 14:23:56 +0000 (14:23 +0000)
    revision 2.164 of object.c

Whether platform malloc(0) returns NULL has nothing to do with whether
platform realloc(p, 0) returns NULL, so MALLOC_ZERO_RETURNS_NULL can
be correctly undefined yet realloc(p, 0) can return NULL anyway.

Prevent realloc(p, 0) doing free(p) and returning NULL via a different
hack.  Would probably be better to get rid of MALLOC_ZERO_RETURNS_NULL
entirely.

Bugfix candidate.

Objects/object.c

index 58121788691674b2aab6500af38a2994960fd5e5..0541fbda44fec5ae1c70bc280cca85df0a452bbb 100644 (file)
@@ -1888,11 +1888,8 @@ PyMem_Malloc(size_t nbytes)
 void *
 PyMem_Realloc(void *p, size_t nbytes)
 {
-#if _PyMem_EXTRA > 0
-       if (nbytes == 0)
-               nbytes = _PyMem_EXTRA;
-#endif
-       return PyMem_REALLOC(p, nbytes);
+       /* See comment near MALLOC_ZERO_RETURNS_NULL in pyport.h. */
+       return PyMem_REALLOC(p, nbytes ? nbytes : 1);
 }
 
 void