git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Must not modify the_index.cache as it may be passed to realloc at some point.
@ 2007-10-03  5:44 Keith Packard
  2007-10-03  5:55 ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Keith Packard @ 2007-10-03  5:44 UTC (permalink / raw)
  To: Git Mailing List; +Cc: keithp

[-- Attachment #1: Type: text/plain, Size: 1277 bytes --]

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.
---
 builtin-ls-files.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 6c1db86..0028b8a 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -280,7 +280,7 @@ static void prune_cache(const char *prefix)
 
        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;
-- 
1.5.3.3.131.g34c6d-dirty

-- 
keith.packard@intel.com

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-10-03 22:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-03  5:44 [PATCH] Must not modify the_index.cache as it may be passed to realloc at some point Keith Packard
2007-10-03  5:55 ` Junio C Hamano
2007-10-03  7:03   ` [PATCH] Add test case for ls-files --with-head Carl Worth
2007-10-03 12:09     ` Johannes Sixt
2007-10-03 15:36       ` Johannes Schindelin
2007-10-03 15:52         ` David Kastrup
2007-10-03 16:06         ` Carl Worth
2007-10-03 16:15           ` David Kastrup
2007-10-03 20:21             ` Jeff King
2007-10-03 21:39               ` Johannes Schindelin
2007-10-03 21:47                 ` Junio C Hamano
2007-10-03 22:11                   ` Jeff King
2007-10-03 19:29           ` Junio C Hamano
2007-10-03 15:50       ` Carl Worth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).