[BusyBox] bug in cut in 0.60.2
Matt Kraai
kraai at alumni.cmu.edu
Tue Feb 26 09:16:03 UTC 2002
On Tue, Feb 26, 2002 at 05:08:26PM +0100, Axel Kittenberger wrote:
>
> > I don't see this error. My libc must be returning a non-NULL
> > value for zero-length allocations.
>
> I believe the ANSI standard does not specify how malloc should behave on
> allocations of size 0. Some implementations return NULL, some return a memory
> block that must also be freed again. (It takes up space in the heap frames).
> So if you allocated it you must free it either way, if it's implementation B
> free(NULL) does not hurt.
>
> Some thing I've also already seen in some foreign source is
>
> void * xmalloc(size_t size)
> {
> if (size == 0) {
> size = 1;
> }
> return malloc(size)
> }
>
> This way you can be sure that you'll always get a non NULL pointer, with the
> cost of an additional wasted byte per 0 allocation (beside the heap frame).
I don't see why we need to guarantee that the pointer we return
isn't NULL. Would someone please enlighten me?
Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20020226/6cbcb29f/attachment.pgp
More information about the busybox
mailing list