@@ -14,8 +14,13 @@ struct trace_key trace_fsmonitor = TRACE_KEY_INIT(FSMONITOR);
1414static void fsmonitor_ewah_callback (size_t pos , void * is )
1515{
1616 struct index_state * istate = (struct index_state * )is ;
17- struct cache_entry * ce = istate -> cache [ pos ] ;
17+ struct cache_entry * ce ;
1818
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 ];
1924 ce -> ce_flags &= ~CE_FSMONITOR_VALID ;
2025}
2126
@@ -50,17 +55,24 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
5055 }
5156 istate -> fsmonitor_dirty = fsmonitor_dirty ;
5257
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+
5362 trace_printf_key (& trace_fsmonitor , "read fsmonitor extension successful" );
5463 return 0 ;
5564}
5665
5766void fill_fsmonitor_bitmap (struct index_state * istate )
5867{
59- unsigned int i ;
68+ unsigned int i , skipped = 0 ;
6069 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+ }
6476}
6577
6678void 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)
7183 uint32_t ewah_size = 0 ;
7284 int fixup = 0 ;
7385
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+
7490 put_be32 (& hdr_version , INDEX_EXTENSION_VERSION );
7591 strbuf_add (sb , & hdr_version , sizeof (uint32_t ));
7692
@@ -236,6 +252,9 @@ void tweak_fsmonitor(struct index_state *istate)
236252 }
237253
238254 /* 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 );
239258 ewah_each_bit (istate -> fsmonitor_dirty , fsmonitor_ewah_callback , istate );
240259
241260 /* Now mark the untracked cache for fsmonitor usage */
0 commit comments