RFC: Handling realloc(0)
Hannes Domani
ssbssa@yahoo.de
Fri Apr 30 17:48:31 GMT 2021
Am Freitag, 30. April 2021, 19:02:40 MESZ hat Nick Clifton via Binutils <binutils@sourceware.org> Folgendes geschrieben:
> 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)
> bfd_realloc (ptr, 0) will return 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
>
>
> @@ -296,23 +319,59 @@ bfd_realloc (void *ptr, bfd_size_type size)
> return NULL;
> }
>
> + /* The behaviour of realloc(0) is implementation defined,
> + but for this function we always allocate memory. */
> + if (size == 0)
> + size = 1;
> ret = realloc (ptr, sz);
I think you meant to use sz here instead of size.
Regards
Hannes
More information about the Binutils
mailing list