git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] bulk-checkin: zero-initialize hashfile_checkpoint

From
Jeff King <peff@peff.net>
Date
Sep 5, 2019, 22:52 UTC
Message-ID
<20190905225249.GC25657@sigill.intra.peff.net>
In-Reply-To
<20190905224859.GA28660@sigill.intra.peff.net>

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 <s-beyer@gmx.net>
Signed-off-by: Jeff King <peff@peff.net>
---
We could also have a HASHFILE_CHECKPOINT_INIT, but it seemed like
overkill. I dunno.
 bulk-checkin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 39ee7d6107..583aacb9e3 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -197,7 +197,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
 	git_hash_ctx ctx;
 	unsigned char obuf[16384];
 	unsigned header_len;
-	struct hashfile_checkpoint checkpoint;
+	struct hashfile_checkpoint checkpoint = {0};
 	struct pack_idx_entry *idx = NULL;
 
 	seekback = lseek(fd, 0, SEEK_CUR);
-- 
2.23.0.463.g883b23b1c5
Previous: Jeff KingNext: Jeff King
Message 15 of 23 in “Fix maybe-uninitialized warnings found by gcc 9 -flto”
  1. Fix maybe-uninitialized warnings found by gcc 9 -fltoStephan Beyer, Sep 5, 2019
  2. René ScharfeSep 5, 2019
  3. Jeff KingSep 5, 2019
  4. René ScharfeSep 5, 2019
  5. Junio C HamanoSep 5, 2019
  6. René ScharfeSep 5, 2019
  7. Junio C HamanoSep 5, 2019
  8. Junio C HamanoSep 5, 2019
  9. Junio C HamanoSep 5, 2019
  10. Jeff KingSep 5, 2019
  11. Junio C HamanoSep 5, 2019
  12. Jeff KingSep 5, 2019
  13. 1/6 git-am: handle missing "author" when parsing commitJeff King, Sep 5, 2019
  14. 2/6 pack-objects: use object_id in packlist_alloc()Jeff King, Sep 5, 2019
  15. 3/6 bulk-checkin: zero-initialize hashfile_checkpointJeff King, Sep 5, 2019
  16. 4/6 diff-delta: set size out-parameter to 0 for NULL deltaJeff King, Sep 5, 2019
  17. Stephan BeyerSep 5, 2019
  18. Jeff KingSep 5, 2019
  19. Stephan BeyerSep 5, 2019
  20. Jeff KingSep 6, 2019
  21. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 6, 2019
  22. 5/6 test-read-cache: drop namelen variableJeff King, Sep 5, 2019
  23. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.