{"thread":{"id":"8360","subject":"[PATCH 2/3] Ensure the pack index is opened before access","startedAt":"2007-05-30T06:13:14Z","lastAt":"2007-05-30T06:13:14Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"43618","messageId":"20070530061314.GB12738@spearce.org","threadId":"8360","inReplyTo":null,"subject":"[PATCH 2/3] Ensure the pack index is opened before access","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-05-30T06:13:14Z","receivedAt":"2007-05-30T06:13:14Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"In this particular location of fsck the index should have already\nbeen opened by verify_pack, which is called just before we get\nhere and loop through the object names.  However, just in case a\nfuture version of that function does not use the index file we'll\ndouble-check its open before we access the num_objects field.\n\nBetter safe now than sorry later.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fsck.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex cbbcaf0..9959818 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -668,7 +668,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)\n \t\t\tverify_pack(p, 0);\n \n \t\tfor (p = packed_git; p; p = p->next) {\n-\t\t\tuint32_t i, num = p->num_objects;\n+\t\t\tuint32_t i, num;\n+\t\t\tif (open_pack_index(p))\n+\t\t\t\tcontinue;\n+\t\t\tnum = p->num_objects;\n \t\t\tfor (i = 0; i < num; i++)\n \t\t\t\tfsck_sha1(nth_packed_object_sha1(p, i));\n \t\t}\n-- \n1.5.2.869.g6b3ba\n"}]}