This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: free() and implicit conversion to a function pointer (was: Use of initialized variable in strtod.c)
- From: Bob Dunlop <bob dot dunlop at xyzzy dot org dot uk>
- To: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- Cc: newlib at sourceware dot org
- Date: Thu, 16 Mar 2017 16:22:58 +0000
- Subject: Re: free() and implicit conversion to a function pointer (was: Use of initialized variable in strtod.c)
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8nz1-77rgpZ_Q2-M8tW3CLg4gMjshR+HNDsgEZLQ=tezQ@mail.gmail.com> <20170316083958.GC16777@calimero.vinschen.de> <15a1051f-f3ae-5bd6-9b6c-4b284ed73704@oarcorp.com>
On Thu, Mar 16 at 10:04, Joel Sherrill wrote:
>
> On 3/16/2017 3:39 AM, Corinna Vinschen wrote:
> > On Mar 15 18:48, Jeffrey Walton wrote:
> >>> But this in __call_atexit.c is definitely correct. It is
> >>> treating free() as a weak symbol and the only way to
> >>> silence Coverity is to add an annotation.
> >>>
> >>> 136 /* Don't dynamically free the atexit array if free is not
> >>> 137 available. */
> >>>
> >>> CID 175323 (#1 of 1): Function address comparison (BAD_COMPARE)
> >>> func_conv: This implicit conversion to a function pointer is suspicious:
> >>> free.
> >>> Did you intend to call free?
> >>> 138 if (!free)
> >>> 139 break;
> >>
> >> Well, I have not encountered that one (yet). Since Coverity is
> >> complaining about an implicit conversion, maybe the following will
> >> help to avoid the implicit part (and sidestep the finding):
> >>
> >> if (free != NULL)
> >> break;
> >>
> >> Or perhaps:
> >>
> >> if ((void*)free != NULL)
> >> break;
> >>
> >> If that works to clear the finding, then it is one of those items I
> >> write-off as "working and playing well with the tools".
> >
> > Unfortunately you have to tell covreity that "free" is a var, not a function,
> > but since that's not generally true... marking as false positive.
> >
>
> Looks like the second option resolves the issue. No Coverity specific
> markup at all. It seems better to be explicit since comparing a function
> name to NULL directly is rather unusual.
>
> --joel
Have you not just inverted the sense of the test as well.
Shouldn't it be:
if ((void*)free == NULL)
break;
--
Bob Dunlop