• Tom Lane's avatar
    Work around unportable behavior of malloc(0) and realloc(NULL, 0). · 09ac603c
    Tom Lane authored
    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.
    09ac603c
common.c 36.8 KB