Skip to content

Commit 7140414

Browse files
peffgitster
authored andcommitted
bulk-checkin: zero-initialize hashfile_checkpoint
We declare a "struct hashfile_checkpoint" but only sometimes actually call hashfile_checkpoint() on it. That makes it not immediately obvious that it's valid when we later access its members. In fact, the code is fine: we fill it in unconditionally in the while(1) loop as long as "idx" is non-NULL. And then if "idx" is NULL, we exit early from the function (because we're just computing the hash, not actually writing), before we look at the struct. However, this does seem to confuse gcc 9.2.1's -Wmaybe-uninitialized when compiled with "-flto -O2" (probably because with LTO it can now realize that our call to hashfile_truncate() does not set the members either). Let's zero-initialize the struct to tell the compiler, as well as any readers of the code, that all is well. Reported-by: Stephan Beyer <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1cbd03 commit 7140414

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bulk-checkin.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
197197
git_hash_ctx ctx;
198198
unsigned char obuf[16384];
199199
unsigned header_len;
200-
struct hashfile_checkpoint checkpoint;
200+
struct hashfile_checkpoint checkpoint = {0};
201201
struct pack_idx_entry *idx = NULL;
202202

203203
seekback = lseek(fd, 0, SEEK_CUR);

0 commit comments

Comments
 (0)