RFC: Handling realloc(0)
Howard Chu
hyc@symas.com
Fri Apr 30 17:51:48 GMT 2021
Nick Clifton via Binutils wrote:
> Hi Guys,
>
> A recent binutils bug report (PR 27797) has brought to light the fact
> that the behaviour of realloc(0) is not well defined. So I am
> proposing the attached patch to change the behaviour of the
> bfd_realloc and bfd_realloc_or_free functions. With this patch
> applied:
>
> bfd_realloc (NULL, 0) will return bfd_malloc (1)
Is bfd_malloc(0) also treated as bfd_malloc(1) ?
> bfd_realloc (ptr, 0) will return ptr
Shouldn't this return NULL? a standard realloc(ptr, 0) == free(ptr).
> bfd_realloc_of_free (NULL, 0) will return NULL (and no error set)
> bfd_realloc_or_free (ptr, 0) will return NULL and ptr will have been freed.
>
> What do people think ? Any objections ?
>
> Cheers
> Nick
>
> bfd/ChangeLog
> 2021-04-30 Nick Clifton <nickc@redhat.com>
>
> * libbfd.c (bfd_realloc): Provide some documentation. Treat a
> size of 0 as a size of 1.
> (bfd_realloc_or_free): Provide some documentation. Treat a size
> of 0 as a request to free.
> * libbfd-in.h (bfd_realloc): Remove prototype.
> (bfd_realloc_or_free): Remove prototype.
> * libbfd.h: Regenerate.
>
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/
More information about the Binutils
mailing list