[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:1.9.2.15) 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:
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?
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- proper realloc(p,0) behavior?,
Eric Blake <=
- Re: proper realloc(p,0) behavior?, Paul Eggert, 2011/03/24
- Re: proper realloc(p,0) behavior?, Jim Meyering, 2011/03/24
- Re: proper realloc(p,0) behavior?, Eric Blake, 2011/03/24
- Re: proper realloc(p,0) behavior?, Paul Eggert, 2011/03/24
- Re: proper realloc(p,0) behavior?, Paolo Bonzini, 2011/03/25
- Re: proper realloc(p,0) behavior?, Eric Blake, 2011/03/25
- Re: proper realloc(p,0) behavior?, Paolo Bonzini, 2011/03/25
- Re: proper realloc(p,0) behavior?, Eric Blake, 2011/03/25
- Re: proper realloc(p,0) behavior?, Paul Eggert, 2011/03/25
- Re: proper realloc(p,0) behavior?, Eric Blake, 2011/03/25