From 11d0be23c481f2df2e03e804c611a0f7d2be1599 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 12 May 2017 10:01:43 +0200 Subject: [PATCH] index: set last entry when reading compressed entries To calculate the path of a compressed index entry, we need to know the preceding entry's path. While we do actually set the first predecessor correctly to "", we fail to update this while reading the entries. Fix the issue by updating `last` inside of the loop. Previously, we've been passing a double-pointer to `read_entry`, which it didn't update. As it is more obvious to update the pointer inside the loop itself, though, we can simply convert it to a normal pointer. --- src/index.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.c b/src/index.c index f5115a62d..110760c9c 100644 --- a/src/index.c +++ b/src/index.c @@ -2287,7 +2287,7 @@ static size_t read_entry( git_index *index, const void *buffer, size_t buffer_size, - const char **last) + const char *last) { size_t path_length, entry_size; const char *path_ptr; @@ -2357,7 +2357,7 @@ static size_t read_entry( size_t varint_len; size_t strip_len = git_decode_varint((const unsigned char *)path_ptr, &varint_len); - size_t last_len = strlen(*last); + size_t last_len = strlen(last); size_t prefix_len = last_len - strip_len; size_t suffix_len = strlen(path_ptr + varint_len); size_t path_len; @@ -2448,7 +2448,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size) unsigned int i; struct index_header header = { 0 }; git_oid checksum_calculated, checksum_expected; - const char **last = NULL; + const char *last = NULL; const char *empty = ""; #define seek_forward(_increase) { \ @@ -2472,7 +2472,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size) index->version = header.version; if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = ∅ + last = empty; seek_forward(INDEX_HEADER_SIZE); @@ -2507,6 +2507,9 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size) } error = 0; + if (index->version >= INDEX_VERSION_NUMBER_COMP) + last = entry->path; + seek_forward(entry_size); }