]> granicus.if.org Git - postgresql/commit
Work around unportable behavior of malloc(0) and realloc(NULL, 0).
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2012 21:31:49 +0000 (17:31 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2012 21:31:49 +0000 (17:31 -0400)
commit689d99306a1838728075928fcc61ca3ffc112384
tree7d8ca33f843125ce5492d0b626a0626a04c1df43
parent87b6a3989fec4a8d10de910671ab702e07aa85cf
Work around unportable behavior of malloc(0) and realloc(NULL, 0).

On some platforms these functions return NULL, rather than the more common
practice of returning a pointer to a zero-sized block of memory.  Hack our
various wrapper functions to hide the difference by substituting a size
request of 1.  This is probably not so important for the callers, who
should never touch the block anyway if they asked for size 0 --- but it's
important for the wrapper functions themselves, which mistakenly treated
the NULL result as an out-of-memory failure.  This broke at least pg_dump
for the case of no user-defined aggregates, as per report from
Matthew Carrington.

Back-patch to 9.2 to fix the pg_dump issue.  Given the lack of previous
complaints, it seems likely that there is no live bug in previous releases,
even though some of these functions were in place before that.
contrib/oid2name/oid2name.c
contrib/pg_upgrade/util.c
contrib/pgbench/pgbench.c
src/backend/utils/misc/guc.c
src/bin/initdb/initdb.c
src/bin/pg_basebackup/streamutil.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/dumpmem.c
src/bin/psql/common.c
src/bin/psql/print.c
src/port/dirmod.c