-fanalyzer: Questions on C vs CPP + use of GCC attr's like malloc()/access()
David Malcolm
dmalcolm@redhat.com
Sat Nov 26 18:51:15 GMT 2022
On Sat, 2022-11-26 at 17:47 +0000, Jonathan Wakely wrote:
> On Sat, 26 Nov 2022, 15:48 Gavin Ray, <ray.gavin97@gmail.com> wrote:
>
> > I was using if (fd != -1) and was still getting the warning which
> > confused
> > me
> > My suggestion was maybe to add the exact condition the fd analyzer
> > is
> > looking for to the warning so that folks know how to fix it/trigger
> > its 'true' branch.
> >
> > e.g. instead of:
> > "fd may not be valid"
> >
> > Something like this, or thereabouts:
> > "fd may not be valid (expecting fd >= 0)"
> >
>
> That seems like an analyzer bug, checking for -1 should be ok. POSIX
> is
> clear that open and socket return -1 on error. I didn't check all the
> other
> functions that return new file descriptors, but I think they're the
> same.
Looking at sm-fd.cc: fd_state_machine::on_condition it looks like the
analyzer handles both checks against -1 (eq/ne) *and* checks for >= 0,
so maybe the .dot file needs updating.
Gavin, if you have a reproducer in C [1] where the wording of the
message seems "off", please can you file it in bugzilla and I'll take a
look next week. The fd state machine is new in GCC 13, so it's
interesting to get this into the hands of end-users.
Thanks
Dave
[1] Sadly, C++ in -fanalyzer is sufficiently broken right now that it's
not worth filing extra bugs on top of the ones I already know about,
alas.
More information about the Gcc
mailing list