[PATCH v6 2/3] support: Add xreallocarray

Paul Eggert eggert@cs.ucla.edu
Fri Mar 10 21:21:56 GMT 2023


On 2023-03-10 10:44, Adhemerval Zanella Netto wrote:
> 
> 
> On 10/03/23 13:49, Florian Weimer wrote:
>> * Adhemerval Zanella:
>>
>>> +void *
>>> +xreallocarray (void *p, size_t n, size_t s)
>>> +{
>>> +  void *r = reallocarray (p, n, s);
>>> +  if (r == NULL)
>>> +    oom_error ("reallocarray", n);
>>> +  return r;
>>> +}
>>
>> Isn't the failure condition more complicated?  See xrealloc.
> 
> Indeed, I will update the patch.

You can steal the source code from Gnulib, which already has 
xreallocarray in lib/xmalloc.c.

(Gnulib also has an xireallocarray which is better if you're worried 
about integer overflow, but one step at a time.)


More information about the Libc-alpha mailing list