[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proper realloc(p,0) behavior?

From: Eric Blake
Subject: proper realloc(p,0) behavior?
Date: Thu, 24 Mar 2011 11:17:12 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9

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:

Uli refuses to fix glibc (but somehow I'm not surprised):

How should gnulib react?  And are there any existing GNU programs that
would break if C99 realloc semantics were enforced?

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]