3 ms·
Issue: the function should be treating nmemb == 0 or size == 0 as errors rather than a feature. The way it is, you can do /* obfuscated way of doing free(
by kazinator 12y ago
Issue: the function should be treating nmemb == 0 or size == 0 as errors rather than a feature.
The way it is, you can do
/* obfuscated way of doing free(ptr); */
realloc_array(ptr, 0, whatever);
There is no need to carry on the tradition that realloc serves as a complete memory allocator in a single function.
The program could be pass nmemb or size as zero due to a bug, rather than the intent to free.
Or as a compromise, zero could be accepted for nmemb (zero sized array), but not for size (the base elements must have nonzero sizes).