[BusyBox] bug in cut in 0.60.2

Axel Kittenberger Axel.Kittenberger at maxxio.at
Tue Feb 26 09:09:04 UTC 2002


> 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).



More information about the busybox mailing list