{"thread":{"id":"26342","subject":"[PATCH] fsck: drop unused parameter from traverse_one_object()","startedAt":"2011-01-26T20:46:55Z","lastAt":"2011-01-26T20:46:55Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"159912","messageId":"7vy667jsu8.fsf@alter.siamese.dyndns.org","threadId":"26342","inReplyTo":null,"subject":"[PATCH] fsck: drop unused parameter from traverse_one_object()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-26T20:46:55Z","receivedAt":"2011-01-26T20:46:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Also add comments to seemingly unsafe pointer dereferences, that\nare all safe.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fsck.c |   13 ++++++++++---\n 1 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 6d5ebca..91409a0 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -74,7 +74,13 @@ static int mark_object(struct object *obj, int type, void *data)\n {\n \tstruct object *parent = data;\n \n+\t/*\n+\t * The only case data is NULL or type is OBJ_ANY is when\n+\t * mark_object_reachable() calls us.  All the callers of\n+\t * that function has non-NULL obj hence ...\n+\t */\n \tif (!obj) {\n+\t\t/* ... these references to parent->fld are safe here */\n \t\tprintf(\"broken link from %7s %s\\n\",\n \t\t\t   typename(parent->type), sha1_to_hex(parent->sha1));\n \t\tprintf(\"broken link from %7s %s\\n\",\n@@ -84,6 +90,7 @@ static int mark_object(struct object *obj, int type, void *data)\n \t}\n \n \tif (type != OBJ_ANY && obj->type != type)\n+\t\t/* ... and the reference to parent is safe here */\n \t\tobjerror(parent, \"wrong object type in link\");\n \n \tif (obj->flags & REACHABLE)\n@@ -109,7 +116,7 @@ static void mark_object_reachable(struct object *obj)\n \tmark_object(obj, OBJ_ANY, NULL);\n }\n \n-static int traverse_one_object(struct object *obj, struct object *parent)\n+static int traverse_one_object(struct object *obj)\n {\n \tint result;\n \tstruct tree *tree = NULL;\n@@ -138,7 +145,7 @@ static int traverse_reachable(void)\n \t\tentry = pending.objects + --pending.nr;\n \t\tobj = entry->item;\n \t\tparent = (struct object *) entry->name;\n-\t\tresult |= traverse_one_object(obj, parent);\n+\t\tresult |= traverse_one_object(obj);\n \t}\n \treturn !!result;\n }\n@@ -556,8 +563,8 @@ static int fsck_cache_tree(struct cache_tree *it)\n \t\t\t      sha1_to_hex(it->sha1));\n \t\t\treturn 1;\n \t\t}\n-\t\tmark_object_reachable(obj);\n \t\tobj->used = 1;\n+\t\tmark_object_reachable(obj);\n \t\tif (obj->type != OBJ_TREE)\n \t\t\terr |= objerror(obj, \"non-tree in cache-tree\");\n \t}\n-- \n1.7.4.rc3.259.g12451\n"}]}