summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 96e24ab)
raw | patch | inline | side by side (parent: 96e24ab)
author | Keith Packard <keithp@keithp.com> | |
Wed, 3 Oct 2007 05:44:15 +0000 (22:44 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 3 Oct 2007 06:18:58 +0000 (23:18 -0700) |
The index cache is not static, growing as new entries are added. If
entries are added after prune_cache is called, cache will no longer
point at the base of the allocation, and realloc will not be happy.
I verified that this was the only place in the current source which
modified any index_state.cache elements aside from the alloc/realloc
calls in read-cache by changing the type of the element to 'struct
cache_entry ** const cache' and recompiling.
A more efficient patch would create a separate 'cache_base' value to
track the allocation and then fix things up when reallocation was
necessary, instead of the brute-force memmove used here.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
entries are added after prune_cache is called, cache will no longer
point at the base of the allocation, and realloc will not be happy.
I verified that this was the only place in the current source which
modified any index_state.cache elements aside from the alloc/realloc
calls in read-cache by changing the type of the element to 'struct
cache_entry ** const cache' and recompiling.
A more efficient patch would create a separate 'cache_base' value to
track the allocation and then fix things up when reallocation was
necessary, instead of the brute-force memmove used here.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-ls-files.c | patch | blob | history |
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 6c1db86e8056285cb25359d55f5ebf9dd0e6f489..171d449048d304b043ed33776fab4bf95434e30a 100644 (file)
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
if (pos < 0)
pos = -pos-1;
- active_cache += pos;
+ memmove(active_cache, active_cache + pos,
+ (active_nr - pos) * sizeof(struct cache_entry *));
active_nr -= pos;
first = 0;
last = active_nr;