@matheusbsbs / matheus-bagliano / commits / a1cdc25172
Fork 0

fsck: drop unused parameter from traverse_one_object()

Also add comments to seemingly unsafe pointer dereferences, that are all safe. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 26, 2011 at 12:46 UTC a1cdc251728b4a2553e38a5427851b14643c7649
1 file changed +10 -3
builtin/fsck.c
+10 -3
@@ -74,7 +74,13 @@ static int mark_object(struct object *obj, int type, void *data)
74 {
75 struct object *parent = data;
76
77 + /*
78 + * The only case data is NULL or type is OBJ_ANY is when
79 + * mark_object_reachable() calls us. All the callers of
80 + * that function has non-NULL obj hence ...
81 + */
82 if (!obj) {
83 + /* ... these references to parent->fld are safe here */
84 printf("broken link from %7s %s\n",
85 typename(parent->type), sha1_to_hex(parent->sha1));
86 printf("broken link from %7s %s\n",
@@ -84,6 +90,7 @@ static int mark_object(struct object *obj, int type, void *data)
90 }
91
92 if (type != OBJ_ANY && obj->type != type)
93 + /* ... and the reference to parent is safe here */
94 objerror(parent, "wrong object type in link");
95
96 if (obj->flags & REACHABLE)
@@ -109,7 +116,7 @@ static void mark_object_reachable(struct object *obj)
116 mark_object(obj, OBJ_ANY, NULL);
117 }
118
112 -static int traverse_one_object(struct object *obj, struct object *parent)
119 +static int traverse_one_object(struct object *obj)
120 {
121 int result;
122 struct tree *tree = NULL;
@@ -138,7 +145,7 @@ static int traverse_reachable(void)
145 entry = pending.objects + --pending.nr;
146 obj = entry->item;
147 parent = (struct object *) entry->name;
141 - result |= traverse_one_object(obj, parent);
148 + result |= traverse_one_object(obj);
149 }
150 return !!result;
151 }
@@ -556,8 +563,8 @@ static int fsck_cache_tree(struct cache_tree *it)
563 sha1_to_hex(it->sha1));
564 return 1;
565 }
559 - mark_object_reachable(obj);
566 obj->used = 1;
567 + mark_object_reachable(obj);
568 if (obj->type != OBJ_TREE)
569 err |= objerror(obj, "non-tree in cache-tree");
570 }