On Thu, 2023-02-16 at 22:48 -0500, Siddhesh Poyarekar wrote: > On 2023-02-16 10:15, David Malcolm via Gcc wrote: > > I'm not convinced that it's useful to the end-user to warn about > > the > > "use of q itself" case. > > FWIW, -Wuse-after-free=3 already should do this: > > At level 3, the warning also diagnoses uses of indeterminate pointers > in > equality expressions. All uses of indeterminate pointers are > undefined > but equality tests sometimes appear after > calls to "realloc" as an attempt to determine whether the call > resulted > in relocating the object to a different address. They are diagnosed > at > a separate level to aid legacy code gradually > transition to safe alternatives.
This is possibly a silly question, but what *are* these safe alternatives? [1] How does one test to see if an object has been reallocated? Dave [1] Would suggesting "rust" here be too snarky? :-P > For example, the equality test in the > function below is diagnosed at this level: > > Jakub and I had discussed this in the context of _FORTIFY_SOURCE=3 > (which is anal about this and can break things) and we got pr#105217, > but that is also a best-effort thing, not really a guarantee. > > IMO the analyzer should go that extra mile and warn for the use of q > itself and maybe deprecate -Wuse-after-free=3 in its favour. > > Sid >