@@ -14,8 +14,13 @@ struct trace_key trace_fsmonitor = TRACE_KEY_INIT(FSMONITOR);
14
14
static void fsmonitor_ewah_callback (size_t pos , void * is )
15
15
{
16
16
struct index_state * istate = (struct index_state * )is ;
17
- struct cache_entry * ce = istate -> cache [ pos ] ;
17
+ struct cache_entry * ce ;
18
18
19
+ if (pos >= istate -> cache_nr )
20
+ BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX " >= %u)" ,
21
+ (uintmax_t )pos , istate -> cache_nr );
22
+
23
+ ce = istate -> cache [pos ];
19
24
ce -> ce_flags &= ~CE_FSMONITOR_VALID ;
20
25
}
21
26
@@ -50,17 +55,24 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
50
55
}
51
56
istate -> fsmonitor_dirty = fsmonitor_dirty ;
52
57
58
+ if (istate -> fsmonitor_dirty -> bit_size > istate -> cache_nr )
59
+ BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX " > %u)" ,
60
+ (uintmax_t )istate -> fsmonitor_dirty -> bit_size , istate -> cache_nr );
61
+
53
62
trace_printf_key (& trace_fsmonitor , "read fsmonitor extension successful" );
54
63
return 0 ;
55
64
}
56
65
57
66
void fill_fsmonitor_bitmap (struct index_state * istate )
58
67
{
59
- unsigned int i ;
68
+ unsigned int i , skipped = 0 ;
60
69
istate -> fsmonitor_dirty = ewah_new ();
61
- for (i = 0 ; i < istate -> cache_nr ; i ++ )
62
- if (!(istate -> cache [i ]-> ce_flags & CE_FSMONITOR_VALID ))
63
- ewah_set (istate -> fsmonitor_dirty , i );
70
+ for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
71
+ if (istate -> cache [i ]-> ce_flags & CE_REMOVE )
72
+ skipped ++ ;
73
+ else if (!(istate -> cache [i ]-> ce_flags & CE_FSMONITOR_VALID ))
74
+ ewah_set (istate -> fsmonitor_dirty , i - skipped );
75
+ }
64
76
}
65
77
66
78
void write_fsmonitor_extension (struct strbuf * sb , struct index_state * istate )
@@ -71,6 +83,10 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
71
83
uint32_t ewah_size = 0 ;
72
84
int fixup = 0 ;
73
85
86
+ if (istate -> fsmonitor_dirty -> bit_size > istate -> cache_nr )
87
+ BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX " > %u)" ,
88
+ (uintmax_t )istate -> fsmonitor_dirty -> bit_size , istate -> cache_nr );
89
+
74
90
put_be32 (& hdr_version , INDEX_EXTENSION_VERSION );
75
91
strbuf_add (sb , & hdr_version , sizeof (uint32_t ));
76
92
@@ -236,6 +252,9 @@ void tweak_fsmonitor(struct index_state *istate)
236
252
}
237
253
238
254
/* Mark all previously saved entries as dirty */
255
+ if (istate -> fsmonitor_dirty -> bit_size > istate -> cache_nr )
256
+ BUG ("fsmonitor_dirty has more entries than the index (%" PRIuMAX " > %u)" ,
257
+ (uintmax_t )istate -> fsmonitor_dirty -> bit_size , istate -> cache_nr );
239
258
ewah_each_bit (istate -> fsmonitor_dirty , fsmonitor_ewah_callback , istate );
240
259
241
260
/* Now mark the untracked cache for fsmonitor usage */
0 commit comments