Realloc freed the memory long before the C99 standard.
Realloc freed the memory long before the C99 standard.
Posted Oct 24, 2024 16:05 UTC (Thu) by Wol (subscriber, #4433)Parent article: realloc() and the oversize importance of zero-size objects
I remember reading my Microsoft C v5.1 (from 1991-ish?) where it says realloc with a size of 0 frees the memory and returns NULL.
Imho this is a very good way of assuring safety - if you do not use free, but instead always do "ptr = realloc( ptr, 0)", you will never (absent multiple copies of a pointer) have dangling pointers lying around.
Cheers,
Wol
Posted Oct 24, 2024 18:05 UTC (Thu)
by fman (subscriber, #121579)
[Link] (3 responses)
And further: How (in this context) is NULL *not* a pointer that can be passed to free().
Presumably, both 1) and 2) would free() the incoming argument pointer.
Posted Oct 24, 2024 18:11 UTC (Thu)
by randomguy3 (subscriber, #71063)
[Link] (2 responses)
Posted Oct 24, 2024 18:12 UTC (Thu)
by randomguy3 (subscriber, #71063)
[Link]
Posted Nov 1, 2024 0:50 UTC (Fri)
by kelnos (subscriber, #174370)
[Link]
I know no one actually interprets or implements it that way, but to me, that's still a valid reading of the spec.
Realloc freed the memory long before the C99 standard.
So in this regard 2) is just a specialization of 1)
Realloc freed the memory long before the C99 standard.
Realloc freed the memory long before the C99 standard.
Realloc freed the memory long before the C99 standard.