From: Jeff Law <law@redhat.com>
To: Samuel Thibault <samuel.thibault@gnu.org>,
GNU C Library <libc-alpha@sourceware.org>
Subject: Re: Coping with gcc warning due to limitation of gcc analysis?
Date: Sun, 28 Jan 2018 10:58:00 -0000 [thread overview]
Message-ID: <bf25fd3d-145e-a829-802d-4605c6c72767@redhat.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2018-01-27 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-28 2:03 Samuel Thibault
2018-01-28 10:58 ` Jeff Law [this message]
2018-01-28 14:45 ` Samuel Thibault
2018-01-28 14:49 ` Florian Weimer
2018-01-29 18:26 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bf25fd3d-145e-a829-802d-4605c6c72767@redhat.com \
--to=law@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=samuel.thibault@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).