On Tue, 27 Jul 2010, Richard Henderson wrote:

> On 07/27/2010 11:45 AM, malc wrote:
> >> +    syms = realloc(syms, nsyms * sizeof(*syms));
> > 
> > Realloc can fail here.
> 
> I don't believe it can.  This (pre-existing) statement *reduces*
> the existing allocation of syms.  I'd be surprised if any malloc
> implementation fails on a size reduction.

Life is full of surprises.

realloc$ cat tr.c 
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    void *ptr;

    for (;;) {
        ptr = malloc (2);
        if (!ptr) break;
    }
    printf ("result = %p\n", realloc (ptr, 1));
    return 0;
}
realloc$ \time -v ./a.out 
result = (nil)
        Command being timed: "./a.out"
        User time (seconds): 5.62
        [..snip..]

> That said, I'd be happy enough to eliminate the call entirely.

-- 
mailto:av1...@comtv.ru

Reply via email to