tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Reuse strtonum(3) and reallocarray(3) from OpenBSD
On Tue, Nov 25, 2014 at 01:42:54AM +0100, Kamil Rytarowski wrote:
> Joerg Sonnenberger wrote
> > As with strtonum, reallocarray has enough problems of its own. While it
> > fixes the problem of overflows, it doesn't handle the problem of failing
> > allocations gracefully. If you don't want to make that fatal or leak
> > memory, you still have to use a separate variable. Another issue is that
> > the API as it is doesn't properly deal with zero sized allocations. In
> > short, this API is once again not nearly as useful as it could be and
> > not something I want to see in libc...
> >
> > Joerg
> >
>
> Thank you for your feedback. These functions are meant to handle the overflow class of bugs, otherwise they are equivalent to the standard libc functions.
>
> A graceful failing of allocations is domain specific (panic, exit, recover, sleep, ...).
>
> Please propose an alternative.
bool reallocarray(void **newp, void *oldp, size_t nmemb, size_t size);
which returns true iff no error happened. If nmemb == 0 or size == 0,
newp will either point to a unique allocation of a size 0 or NULL,
depending on malloc flavor. newp is changed only on success, so a
failing allocation will leave the backing store of oldp intact.
Joerg
Home |
Main Index |
Thread Index |
Old Index