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

[PATCH 2/4] fsck: avoid using an uninitialized variable

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 27, 2025, 12:43 UTC
Message-ID
<575b4b2c2b8a5e800bb65b99f1fcdd6aaae63f94.1743079429.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1888.git.1743079429.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In `fsck_commit()`, after counting the authors of a commit, we set the `err` variable either when there was no author, or when there were more than two authors recorded. Then we access the `err` variable to figure out whether we should return early. But if there was exactly one author, that variable is still uninitialized.

Let's just initialize the variable.
This issue was pointed out by CodeQL.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 fsck.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fsck.c b/fsck.c
index 9fc4c25ffd5..ad04b24ff13 100644
--- a/fsck.c
+++ b/fsck.c
@@ -925,7 +925,7 @@ static int fsck_commit(const struct object_id *oid,
 {
 	struct object_id tree_oid, parent_oid;
 	unsigned author_count;
-	int err;
+	int err = 0;
 	const char *buffer_begin = buffer;
 	const char *buffer_end = buffer + size;
 	const char *p;
-- 
gitgitgadget
Previous: Jeff KingNext: Jeff King
Message 4 of 10 in “Initialize a few uninitialized variables”
  1. 0/4 Initialize a few uninitialized variablesJohannes Schindelin via GitGitGadget, Mar 27, 2025
  2. 1/4 cat_one_file(): make it easy to see that the `size` variable is initializedJohannes Schindelin via GitGitGadget, Mar 27, 2025
  3. Jeff KingMar 28, 2025
  4. 2/4 fsck: avoid using an uninitialized variableJohannes Schindelin via GitGitGadget, Mar 27, 2025
  5. Jeff KingMar 28, 2025
  6. 3/4 load_revindex_from_disk(): avoid accessing uninitialized dataJohannes Schindelin via GitGitGadget, Mar 27, 2025
  7. Taylor BlauMar 27, 2025
  8. 4/4 load_pack_mtimes_file(): avoid accessing uninitialized dataJohannes Schindelin via GitGitGadget, Mar 27, 2025
  9. Taylor BlauMar 27, 2025
  10. Johannes SchindelinJul 17, 2025

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.