@@ -74,7 +74,13 @@ static int mark_object(struct object *obj, int type, void *data)
74
74
{
75
75
struct object * parent = data ;
76
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
+ */
77
82
if (!obj ) {
83
+ /* ... these references to parent->fld are safe here */
78
84
printf ("broken link from %7s %s\n" ,
79
85
typename (parent -> type ), sha1_to_hex (parent -> sha1 ));
80
86
printf ("broken link from %7s %s\n" ,
@@ -84,6 +90,7 @@ static int mark_object(struct object *obj, int type, void *data)
84
90
}
85
91
86
92
if (type != OBJ_ANY && obj -> type != type )
93
+ /* ... and the reference to parent is safe here */
87
94
objerror (parent , "wrong object type in link" );
88
95
89
96
if (obj -> flags & REACHABLE )
@@ -109,7 +116,7 @@ static void mark_object_reachable(struct object *obj)
109
116
mark_object (obj , OBJ_ANY , NULL );
110
117
}
111
118
112
- static int traverse_one_object (struct object * obj , struct object * parent )
119
+ static int traverse_one_object (struct object * obj )
113
120
{
114
121
int result ;
115
122
struct tree * tree = NULL ;
@@ -138,7 +145,7 @@ static int traverse_reachable(void)
138
145
entry = pending .objects + -- pending .nr ;
139
146
obj = entry -> item ;
140
147
parent = (struct object * ) entry -> name ;
141
- result |= traverse_one_object (obj , parent );
148
+ result |= traverse_one_object (obj );
142
149
}
143
150
return !!result ;
144
151
}
@@ -556,8 +563,8 @@ static int fsck_cache_tree(struct cache_tree *it)
556
563
sha1_to_hex (it -> sha1 ));
557
564
return 1 ;
558
565
}
559
- mark_object_reachable (obj );
560
566
obj -> used = 1 ;
567
+ mark_object_reachable (obj );
561
568
if (obj -> type != OBJ_TREE )
562
569
err |= objerror (obj , "non-tree in cache-tree" );
563
570
}
0 commit comments