From: Junio C Hamano <gitster@pobox.com>
To: Stephan Beyer <s-beyer@gmx.net>
Cc: Paul Tan <pyokagan@gmail.com>, Jeff King <peff@peff.net>,
"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, 05 Sep 2019 10:41:57 -0700 [thread overview]
Message-ID: <xmqqlfv2r66y.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190905082459.26816-1-s-beyer@gmx.net> (Stephan Beyer's message of "Thu, 5 Sep 2019 10:24:59 +0200")
Stephan Beyer <s-beyer@gmx.net> writes:
> diff --git a/fast-import.c b/fast-import.c
> index b44d6a467e..58f73f9105 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -903,7 +903,8 @@ static int store_object(
> struct object_entry *e;
> unsigned char hdr[96];
> struct object_id oid;
> - unsigned long hdrlen, deltalen;
> + unsigned long hdrlen;
> + unsigned long deltalen = 0;
> git_hash_ctx c;
> git_zstream s;
[in my attempt to imitate Réne...]
In this function, deltalen is used only when delta != NULL, i.e.
if (delta) {
s.next_in = delta;
s.avail_in = deltalen;
} else {
s.next_in = (void *)dat->buf;
s.avail_in = dat->len;
}
...
if (delta) {
...
hdrlen = encode_in_pack_object_header(hdr, sizeof(hdr),
OBJ_OFS_DELTA, deltalen);
...
Could delta become non-NULL without deltalen getting set? We see
these before all uses of delta/deltalen in this function.
if (last && last->data.len && last->data.buf && last->depth < max_depth
&& dat->len > the_hash_algo->rawsz) {
delta_count_attempts_by_type[type]++;
delta = diff_delta(last->data.buf, last->data.len,
dat->buf, dat->len,
&deltalen, dat->len - the_hash_algo->rawsz);
} else
delta = NULL;
If diff_delta() returns non-NULL without touching deltalen, we'd be
in trouble. We see this in delta.h
static inline void *
diff_delta(const void *src_buf, unsigned long src_bufsize,
const void *trg_buf, unsigned long trg_bufsize,
unsigned long *delta_size, unsigned long max_delta_size)
{
struct delta_index *index = create_delta_index(src_buf, src_bufsize);
if (index) {
void *delta = create_delta(index, trg_buf, trg_bufsize,
delta_size, max_delta_size);
free_delta_index(index);
return delta;
}
return NULL;
}
so the question is if create_delta() can return non-NULL without
touching delta_size. In diff-delta.c::create_delta(), *delta_size
is assigned once at the very end, when the function returns a
pointer to an allocated memory 'out'. All the "return" statement
other than that last one literally returns "NULL".
So it seems that this is a case the compiler getting confused.
next prev parent reply other threads:[~2019-09-05 17:42 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 [this message]
2019-09-05 17:56 ` Junio C Hamano
2019-09-05 18:03 ` Jeff King
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=xmqqlfv2r66y.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--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).