[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: realloc documentation
From: |
Bruno Haible |
Subject: |
Re: realloc documentation |
Date: |
Tue, 21 Apr 2009 12:37:25 +0200 |
User-agent: |
KMail/1.9.9 |
Pádraig Brady wrote:
> ... then we need to use realloc like this I think:
>
> errno=0
> np = realloc (p, n);
> if (np==NULL && errno==ENOMEM) {
> free (p);
> error ();
> }
>
> I.E. xrealloc etc. should be changed to check ENOMEM as above?
This way of checking realloc's return value is a correct one. But the one
we have in lib/xmalloc.c currently is correct as well. The difference
between the two is when p == NULL && n == 0 on glibc systems. In this case,
- your proposed code realizes that glibc was out of memory and fails,
- the current code returns NULL, like it would do on AIX and OSF/1 systems.
Since xrealloc does not guarantee that xrealloc(NULL,0) != NULL, failing in
this situation on glibc is unnecessary.
Bruno