summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-02-28 11:41:57 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-02-28 11:41:57 -0800
commitdc05d73104fda239fc03342e0b53aa5741c53531 (patch)
treeae0b14cc4f36582fc4b4668c0ebe67864b800c4f /sha1_name.c
parentgit svn: delay importing SVN::Base until it is needed (diff)
parentGit 1.7.0.1 (diff)
downloadtgif-dc05d73104fda239fc03342e0b53aa5741c53531.tar.xz
Merge branch 'maint'
* maint: Git 1.7.0.1 Remove reference to GREP_COLORS from documentation sha1_name: fix segfault caused by invalid index access
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 43884c69b3..bf92417838 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -992,13 +992,15 @@ static void diagnose_invalid_index_path(int stage,
pos = cache_name_pos(filename, namelen);
if (pos < 0)
pos = -pos - 1;
- ce = active_cache[pos];
- if (ce_namelen(ce) == namelen &&
- !memcmp(ce->name, filename, namelen))
- die("Path '%s' is in the index, but not at stage %d.\n"
- "Did you mean ':%d:%s'?",
- filename, stage,
- ce_stage(ce), filename);
+ if (pos < active_nr) {
+ ce = active_cache[pos];
+ if (ce_namelen(ce) == namelen &&
+ !memcmp(ce->name, filename, namelen))
+ die("Path '%s' is in the index, but not at stage %d.\n"
+ "Did you mean ':%d:%s'?",
+ filename, stage,
+ ce_stage(ce), filename);
+ }
/* Confusion between relative and absolute filenames? */
fullnamelen = namelen + strlen(prefix);
@@ -1008,13 +1010,15 @@ static void diagnose_invalid_index_path(int stage,
pos = cache_name_pos(fullname, fullnamelen);
if (pos < 0)
pos = -pos - 1;
- ce = active_cache[pos];
- if (ce_namelen(ce) == fullnamelen &&
- !memcmp(ce->name, fullname, fullnamelen))
- die("Path '%s' is in the index, but not '%s'.\n"
- "Did you mean ':%d:%s'?",
- fullname, filename,
- ce_stage(ce), fullname);
+ if (pos < active_nr) {
+ ce = active_cache[pos];
+ if (ce_namelen(ce) == fullnamelen &&
+ !memcmp(ce->name, fullname, fullnamelen))
+ die("Path '%s' is in the index, but not '%s'.\n"
+ "Did you mean ':%d:%s'?",
+ fullname, filename,
+ ce_stage(ce), fullname);
+ }
if (!lstat(filename, &st))
die("Path '%s' exists on disk, but not in the index.", filename);