On 24/03/11 17:17, Eric Blake wrote: > C99 requires realloc(p,0) to either successfully allocate a 0-sized > array (just like malloc(0)) or to return NULL and leave p unchanged. > > glibc treats realloc(p,0) like free(p) (as permitted by C89), and using > C99 compliant code would thus result in a double-free bug. > > POSIX 2008 is ambiguous - it states that it defers to C99 requirements, > but then has the wording of the C89 implementation that permits glibc > behavior. The proper resolution for POSIX is currently under debate: > http://austingroupbugs.net/view.php?id=400 > > Uli refuses to fix glibc (but somehow I'm not surprised): > http://sourceware.org/bugzilla/show_bug.cgi?id=12547 > > How should gnulib react? And are there any existing GNU programs that > would break if C99 realloc semantics were enforced? >
For reference, here's a related dicussion which I started when trying to figure out how to use realloc(): http://lists.gnu.org/archive/html/bug-gnulib/2009-04/threads.html#00176 cheers, Pádraig.
