RFC: Handling realloc(0)

Nick Clifton nickc@redhat.com
Tue May 4 11:26:39 GMT 2021

Hi Howard,

> Is bfd_malloc(0) also treated as bfd_malloc(1) ?

This is not currently defined, but it should be.  I will update the patch
to enfore bfd_malloc(0) == bfd_malloc(1).

>>      bfd_realloc (ptr, 0)           will return ptr
> Shouldn't this return NULL? a standard realloc(ptr, 0) == free(ptr).

No.  This is the whole point of this patch.  bfd_realloc() only returns NULL
if there is insufficient memory, and it never frees anything.  bfd_realloc_or_free()
on the other hand will free memory if passed a size of 0, and it will return
NULL in this case.


More information about the Binutils mailing list