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

[PATCH 2/3] Ensure the pack index is opened before access

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 30, 2007, 06:13 UTC
Message-ID
<20070530061314.GB12738@spearce.org>

In this particular location of fsck the index should have already been opened by verify_pack, which is called just before we get here and loop through the object names. However, just in case a future version of that function does not use the index file we'll double-check its open before we access the num_objects field.

Better safe now than sorry later.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-fsck.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/builtin-fsck.c b/builtin-fsck.c
index cbbcaf0..9959818 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -668,7 +668,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
 			verify_pack(p, 0);
 
 		for (p = packed_git; p; p = p->next) {
-			uint32_t i, num = p->num_objects;
+			uint32_t i, num;
+			if (open_pack_index(p))
+				continue;
+			num = p->num_objects;
 			for (i = 0; i < num; i++)
 				fsck_sha1(nth_packed_object_sha1(p, i));
 		}
-- 
1.5.2.869.g6b3ba
Message 1 of 1 in “Ensure the pack index is opened before access”
  1. 2/3 Ensure the pack index is opened before accessShawn O. Pearce, May 30, 2007

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.