@@ -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
}
@@ -385,28 +392,34 @@ static void add_sha1_list(unsigned char *sha1, unsigned long ino)
385
392
sha1_list .nr = ++ nr ;
386
393
}
387
394
395
+ static inline int is_loose_object_file (struct dirent * de ,
396
+ char * name , unsigned char * sha1 )
397
+ {
398
+ if (strlen (de -> d_name ) != 38 )
399
+ return 0 ;
400
+ memcpy (name + 2 , de -> d_name , 39 );
401
+ return !get_sha1_hex (name , sha1 );
402
+ }
403
+
388
404
static void fsck_dir (int i , char * path )
389
405
{
390
406
DIR * dir = opendir (path );
391
407
struct dirent * de ;
408
+ char name [100 ];
392
409
393
410
if (!dir )
394
411
return ;
395
412
396
413
if (verbose )
397
414
fprintf (stderr , "Checking directory %s\n" , path );
398
415
416
+ sprintf (name , "%02x" , i );
399
417
while ((de = readdir (dir )) != NULL ) {
400
- char name [100 ];
401
418
unsigned char sha1 [20 ];
402
419
403
420
if (is_dot_or_dotdot (de -> d_name ))
404
421
continue ;
405
- if (strlen (de -> d_name ) == 38 ) {
406
- sprintf (name , "%02x" , i );
407
- memcpy (name + 2 , de -> d_name , 39 );
408
- if (get_sha1_hex (name , sha1 ) < 0 )
409
- break ;
422
+ if (is_loose_object_file (de , name , sha1 )) {
410
423
add_sha1_list (sha1 , DIRENT_SORT_HINT (de ));
411
424
continue ;
412
425
}
@@ -556,8 +569,8 @@ static int fsck_cache_tree(struct cache_tree *it)
556
569
sha1_to_hex (it -> sha1 ));
557
570
return 1 ;
558
571
}
559
- mark_object_reachable (obj );
560
572
obj -> used = 1 ;
573
+ mark_object_reachable (obj );
561
574
if (obj -> type != OBJ_TREE )
562
575
err |= objerror (obj , "non-tree in cache-tree" );
563
576
}
0 commit comments