On Thu, Jun 19, 2025 at 05:38:15PM +0200, Thorsten Glaser wrote:
> On Thu, 19 Jun 2025, Rich Felker wrote:
> 
> >> +       The glibc implementation of realloc() is not consistent with
> >> +       that, and as a consequence, it is dangerous to call
> >> +       realloc(p, 0) in glibc.
> >
> >It's not dangerous if you know what it's doing. Rather it's
> >non-portable.
> 
> Nope.
> 
> It’s actually dangerous in all libcs.
> 
> GCC is a repeat offender of taking things that are Undefined
> Behaviour in C (and GCC 15 even defaults to C23) and optimising
> in a way that breaks programs and libraries that depend on the
> behaviour of the respektive system and libc, which they even
> guarantee.
> 
> This is an unperiodic reminder that GCC lacks a -std=posix2024
> and similar.
> 
> This is also why I was a bit angry that C23 made it UB. Had
> they made it unspecified (POSIX verbiage) / IB (C verbiage),
> implementations could actually do things and compilers would
> not be allowed to break things that rely on it, i.e. it would
> merely have been unportable. But when ISO C says UB it’s not
> unportable, it’s dangerous.

OK, this is a legitimate point in support of "dangerous", but it only
applies with -std=c23 or similar. When targeting an older version of
the language standard, the UB does not apply. It would be interesting
to know if GCC and/or LLVM have any particular intent on this yet. My
hope would be that they wait to react until a better consensus is
achieved.

Rich

Reply via email to