Merge branch 'rs/avoid-overflow-in-midpoint-computation'
authorJunio C Hamano <gitster@pobox.com>
Tue, 9 Jul 2019 22:25:37 +0000 (15:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Jul 2019 22:25:38 +0000 (15:25 -0700)
Code clean-up to avoid signed integer overlaps during binary search.

* rs/avoid-overflow-in-midpoint-computation:
cleanup: fix possible overflow errors in binary search, part 2

1  2 
read-cache.c
diff --combined read-cache.c
index 4dd22f4f6eb60ffa8f7c31a535a14b16fb403e53,4f81fca320c4d6fdb4af5148c52804ac9d5b78a8..c701f7f8b81378104e2732e8bb132144ff82e8f5
@@@ -195,7 -195,7 +195,7 @@@ int match_stat_data(const struct stat_d
   * cache, ie the parts that aren't tracked by GIT, and only used
   * to validate the cache.
   */
 -void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
 +void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st)
  {
        fill_stat_data(&ce->ce_stat_data, st);
  
  
        if (S_ISREG(st->st_mode)) {
                ce_mark_uptodate(ce);
 -              mark_fsmonitor_valid(ce);
 +              mark_fsmonitor_valid(istate, ce);
        }
  }
  
@@@ -549,7 -549,7 +549,7 @@@ static int index_name_stage_pos(const s
        first = 0;
        last = istate->cache_nr;
        while (last > first) {
-               int next = (last + first) >> 1;
+               int next = first + ((last - first) >> 1);
                struct cache_entry *ce = istate->cache[next];
                int cmp = cache_name_stage_compare(name, namelen, stage, ce->name, ce_namelen(ce), ce_stage(ce));
                if (!cmp)
@@@ -728,7 -728,7 +728,7 @@@ int add_to_index(struct index_state *is
        memcpy(ce->name, path, namelen);
        ce->ce_namelen = namelen;
        if (!intent_only)
 -              fill_stat_cache_info(ce, st);
 +              fill_stat_cache_info(istate, ce, st);
        else
                ce->ce_flags |= CE_INTENT_TO_ADD;
  
@@@ -1432,7 -1432,7 +1432,7 @@@ static struct cache_entry *refresh_cach
                         */
                        if (!S_ISGITLINK(ce->ce_mode)) {
                                ce_mark_uptodate(ce);
 -                              mark_fsmonitor_valid(ce);
 +                              mark_fsmonitor_valid(istate, ce);
                        }
                        return ce;
                }
        updated = make_empty_cache_entry(istate, ce_namelen(ce));
        copy_cache_entry(updated, ce);
        memcpy(updated->name, ce->name, ce->ce_namelen + 1);
 -      fill_stat_cache_info(updated, &st);
 +      fill_stat_cache_info(istate, updated, &st);
        /*
         * If ignore_valid is not set, we should leave CE_VALID bit
         * alone.  Otherwise, paths marked with --no-assume-unchanged
@@@ -2037,7 -2037,7 +2037,7 @@@ static void *load_cache_entries_thread(
  }
  
  static unsigned long load_cache_entries_threaded(struct index_state *istate, const char *mmap, size_t mmap_size,
 -                      unsigned long src_offset, int nr_threads, struct index_entry_offset_table *ieot)
 +                                               int nr_threads, struct index_entry_offset_table *ieot)
  {
        int i, offset, ieot_blocks, ieot_start, err;
        struct load_cache_entries_thread_data *data;
@@@ -2198,7 -2198,7 +2198,7 @@@ int do_read_index(struct index_state *i
                ieot = read_ieot_extension(mmap, mmap_size, extension_offset);
  
        if (ieot) {
 -              src_offset += load_cache_entries_threaded(istate, mmap, mmap_size, src_offset, nr_threads, ieot);
 +              src_offset += load_cache_entries_threaded(istate, mmap, mmap_size, nr_threads, ieot);
                free(ieot);
        } else {
                src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset);