Re: [hackers] [st] Add xmalloc and xrealloc wrappers || "Roberto E. Vargas Caballero"

From: Andrew Hills <hills.as_AT_gmail.com>
Date: Thu, 13 Sep 2012 14:18:26 -0400

On Thu, Sep 13, 2012 at 10:37 AM, Joerg Zinke <mail_AT_umaxx.net> wrote:
> This xrealloc() is a good a example for bad c programming.
> Quoting the OpenBSD realloc(3) manpage:
(...)
>> +void *
>> +xrealloc(void *p, size_t len) {
>> + if((p = realloc(p, len)) == NULL)
>> + die("Out of memory");
>> + return p;
>> +}

I don't see how those guidelines apply to xrealloc(). If realloc()
ever fails, the program exits, so there is no memory leak. If you
meant the code calling xrealloc() (formerly calling realloc()), then
it's not xrealloc() that's an example of bad practice. But, "row" and
"col" are already checked for the lower bound; the size of the
structures is known and small, and it is a reasonable assumption that
no one will have a screen resolution high enough to overflow these, or
even come close, so I see no reason to check the upper bound.

--Andrew Hills
Received on Thu Sep 13 2012 - 20:18:26 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 20:24:05 CEST