3 ms·
erm... allocating zero was never a good idea. it had varying behaviours on varying platforms for as long as i could remember and was one of those special cases
by cperciva 11y ago
erm... allocating zero was never a good idea. it had varying behaviours on varying platforms for as long as i could remember and was one of those special cases to avoid.
No, allocating zero bytes is a perfectly reasonable thing to do, as long as you remember that NULL is not necessarily an allocation failure.
if (((buf = malloc(buflen)) == NULL) && (buflen > 0))
goto OUTOFMEMORY;
is perfectly good code.
- jheriko 11y agothats not even close to reasoning imo, its just an assertion. ... but i agree that the code is safer if you check for bad cases. i can't see why allocating zero ever is more sensible than not doing it at all (and therefore avoiding even having to know about this problem, much less deal with it).