From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Stephan Beyer <s-beyer@gmx.net>, Paul Tan <pyokagan@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
"Shawn O. Pearce" <spearce@spearce.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
git@vger.kernel.org
Subject: Re: [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto
Date: Thu, 5 Sep 2019 14:03:48 -0400 [thread overview]
Message-ID: <20190905180348.GC23663@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqd0ger5j7.fsf@gitster-ct.c.googlers.com>
On Thu, Sep 05, 2019 at 10:56:12AM -0700, Junio C Hamano wrote:
> Stephan Beyer <s-beyer@gmx.net> writes:
>
> > diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
> > index 7e79b555de..ef0963e2f4 100644
> > --- a/t/helper/test-read-cache.c
> > +++ b/t/helper/test-read-cache.c
> > @@ -4,7 +4,7 @@
> >
> > int cmd__read_cache(int argc, const char **argv)
> > {
> > - int i, cnt = 1, namelen;
> > + int i, cnt = 1, namelen = 0;
> > const char *name = NULL;
> >
> > if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
> namelen = strlen(name);
>
> The above is the only assignment to namelen in this function, and
> namelen is used like so:
>
> if (name) {
> ...
> pos = index_name_pos(&the_index, name, namelen);
>
> So somebody does not realize that skip_prefix() returns true only
> when it touches name. But skip_prefix() is inline and visible to
> the compiler, and it is quite clear that name is only touched when
> the function returns non-zero.
I said earlier that I wouldn't mind seeing "namelen = 0" here. But I
think there is a much more direct solution: keeping the assignment and
point of use closer together. That makes it more clear both to the
compiler and to a human when we expect the variable to be valid. In
fact, since it's only used once, we can drop the variable altogther. :)
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 7e79b555de..244977a29b 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -4,11 +4,10 @@
int cmd__read_cache(int argc, const char **argv)
{
- int i, cnt = 1, namelen;
+ int i, cnt = 1;
const char *name = NULL;
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
- namelen = strlen(name);
argc--;
argv++;
}
@@ -24,7 +23,7 @@ int cmd__read_cache(int argc, const char **argv)
refresh_index(&the_index, REFRESH_QUIET,
NULL, NULL, NULL);
- pos = index_name_pos(&the_index, name, namelen);
+ pos = index_name_pos(&the_index, name, strlen(name));
if (pos < 0)
die("%s not in index", name);
printf("%s is%s up to date\n", name,
next prev parent reply other threads:[~2019-09-05 18:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-05 8:24 [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto Stephan Beyer
2019-09-05 17:08 ` René Scharfe
2019-09-05 17:53 ` Jeff King
2019-09-05 19:09 ` René Scharfe
2019-09-05 19:25 ` Junio C Hamano
2019-09-05 19:39 ` René Scharfe
2019-09-05 19:50 ` Junio C Hamano
2019-09-05 17:41 ` Junio C Hamano
2019-09-05 17:56 ` Junio C Hamano
2019-09-05 18:03 ` Jeff King [this message]
2019-09-05 18:22 ` Junio C Hamano
2019-09-05 22:48 ` Jeff King
2019-09-05 22:50 ` [PATCH 1/6] git-am: handle missing "author" when parsing commit Jeff King
2019-09-05 22:52 ` [PATCH 2/6] pack-objects: use object_id in packlist_alloc() Jeff King
2019-09-05 22:52 ` [PATCH 3/6] bulk-checkin: zero-initialize hashfile_checkpoint Jeff King
2019-09-05 22:53 ` [PATCH 4/6] diff-delta: set size out-parameter to 0 for NULL delta Jeff King
2019-09-05 22:53 ` [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto Stephan Beyer
2019-09-05 22:58 ` Jeff King
2019-09-05 23:10 ` Stephan Beyer
2019-09-06 1:24 ` Jeff King
2019-09-06 1:36 ` [PATCH v2 6/6] pack-objects: drop packlist index_pos optimization Jeff King
2019-09-05 22:54 ` [PATCH 5/6] test-read-cache: drop namelen variable Jeff King
2019-09-05 22:56 ` [PATCH 6/6] pack-objects: drop packlist index_pos optimization Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190905180348.GC23663@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pyokagan@gmail.com \
--cc=s-beyer@gmx.net \
--cc=sandals@crustytoothpaste.net \
--cc=spearce@spearce.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).