Skip to content

Commit a1cdc25

Browse files
committed
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 <[email protected]>
1 parent d2d434b commit a1cdc25

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

builtin/fsck.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ static int mark_object(struct object *obj, int type, void *data)
7474
{
7575
struct object *parent = data;
7676

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+
*/
7782
if (!obj) {
83+
/* ... these references to parent->fld are safe here */
7884
printf("broken link from %7s %s\n",
7985
typename(parent->type), sha1_to_hex(parent->sha1));
8086
printf("broken link from %7s %s\n",
@@ -84,6 +90,7 @@ static int mark_object(struct object *obj, int type, void *data)
8490
}
8591

8692
if (type != OBJ_ANY && obj->type != type)
93+
/* ... and the reference to parent is safe here */
8794
objerror(parent, "wrong object type in link");
8895

8996
if (obj->flags & REACHABLE)
@@ -109,7 +116,7 @@ static void mark_object_reachable(struct object *obj)
109116
mark_object(obj, OBJ_ANY, NULL);
110117
}
111118

112-
static int traverse_one_object(struct object *obj, struct object *parent)
119+
static int traverse_one_object(struct object *obj)
113120
{
114121
int result;
115122
struct tree *tree = NULL;
@@ -138,7 +145,7 @@ static int traverse_reachable(void)
138145
entry = pending.objects + --pending.nr;
139146
obj = entry->item;
140147
parent = (struct object *) entry->name;
141-
result |= traverse_one_object(obj, parent);
148+
result |= traverse_one_object(obj);
142149
}
143150
return !!result;
144151
}
@@ -556,8 +563,8 @@ static int fsck_cache_tree(struct cache_tree *it)
556563
sha1_to_hex(it->sha1));
557564
return 1;
558565
}
559-
mark_object_reachable(obj);
560566
obj->used = 1;
567+
mark_object_reachable(obj);
561568
if (obj->type != OBJ_TREE)
562569
err |= objerror(obj, "non-tree in cache-tree");
563570
}

0 commit comments

Comments
 (0)