Missed warning (-Wuse-after-free)
Martin Uecker
uecker@tugraz.at
Fri Feb 24 08:52:11 GMT 2023
Am Freitag, dem 24.02.2023 um 03:01 +0000 schrieb Peter Lafreniere:
...
>
> > Maybe it could do an exception for printing, that is, reading a pointer
> > is not a problem in itself, a long as you don't compare it, but I'm not
> > such an expert about this.
>
> One last thought: with the above strict interpretation of the c standard,
> it would become nigh on impossible to implement the malloc(3) family of
> functions in c themselves. I vote for the "shared storage" interpretation
> of the c11 standard that is actually implemented rather than this abstract
> liveness oriented interpretation.
This is a bit of a misunderstanding about what "undefined behavior" means
in ISO C. It simply means that ISO C does not specify the behavior. This
does not mean it is illegal to do something which has undefined behavior.
Instead, it means you can not rely on the ISO C standard for portable
behavior. So if you implement "malloc" in C itself you will probably
rely on "undefined behavior", but this is perfectly fine. The C standard
specifies behavior of "malloc", but does not care how it is implemented.
Martin
More information about the Gcc
mailing list