This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Coping with gcc warning due to limitation of gcc analysis?
- From: Jeff Law <law at redhat dot com>
- To: Samuel Thibault <samuel dot thibault at gnu dot org>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Sat, 27 Jan 2018 14:25:29 -0700
- Subject: Re: Coping with gcc warning due to limitation of gcc analysis?
- Authentication-results: sourceware.org; auth=none
- References: <20180127205417.4eruhvizwf4x2y2c@var.youpi.perso.aquilenet.fr>
On 01/27/2018 01:54 PM, Samuel Thibault wrote:
> Hello,
>
> We have a warning in sysdeps/mach/hurd/getresgid.c:
>
> ../sysdeps/mach/hurd/getresgid.c:57:9: warning: 'saved' may be used uninitialized in this function
>
> Basically the structure of the function is the following:
>
> int
> __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
> {
> gid_t saved;
> ...
>
> err = foo ();
> if (!err)
> {
> if (bar)
> err = EBAR;
> else
> {
> saved = bat;
> }
> }
>
> if (err)
> return err;
>
> *sgid = saved; /* The warning is triggered here */
> ...
> }
>
> i.e. in all the cases where `saved' is not initialized, err is set to
> non-zero, and thus we return before ever using saved.
>
> What is the glibc-preferred way to deal with this? Of course I could
> just initialize saved to a dumb value like -1 but the reader might
> wonder why unless we put a blunt comment, and a smarter compiler might
> later warn "-1 set in `saved' is never used"...
First, make sure you've filed a bug with a reproducer in GCC :-) We
work diligently to address these false positives. It may even be the
case that this is one we've already fixed on the trunk.
Jeff