alx-0029r4 - Restore the traditional realloc(3) specification
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Jun 25 18:07:06 GMT 2025
Hi Alejandro,
> > > > +XXX)
> > > > +While atypical,
> > > > +<b>realloc</b> may fail
> > > > +for a call that shrinks the block of memory.
> > >
> > > Is it worth wording this as "may fail or return a different pointer
> > > for a call that shrinks the block of memory"?
> Oh, the text is still there; I didn't see it. :)
> The realloc function returns a pointer to the new object
> (which can have the same value as a pointer to the old object),
> or a null pointer if the new object has not been allocated
In principle a realloc that shrinks a non-NULL block does never need to fail.
If it can't shrink the current block (either because internal design means it
can't make it any smaller or because it doesn't have memory for a new
smaller block) then it should preferably return the original pointer instead
of returning NULL and taking the failure path.
So I'm wondering whether we should more clearly specify this - whenever
it's possible to not fail, don't return NULL?
Cheers,
Wilco
More information about the Libc-alpha
mailing list