git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Keith Packard <keithp@keithp.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: keithp@keithp.com
Subject: [PATCH] Must not modify the_index.cache as it may be passed to realloc at some point.
Date: Tue, 02 Oct 2007 22:44:15 -0700	[thread overview]
Message-ID: <1191390255.16292.2.camel@koto.keithp.com> (raw)

[-- 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 --]

             reply	other threads:[~2007-10-03  5:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-03  5:44 Keith Packard [this message]
2007-10-03  5:55 ` [PATCH] Must not modify the_index.cache as it may be passed to realloc at some point 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1191390255.16292.2.camel@koto.keithp.com \
    --to=keithp@keithp.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).