Skip to content

Commit 156e28b

Browse files
jeffhostetlergitster
authored andcommitted
sparse-index: pass string length to index_file_exists()
The call to index_file_exists() in the loop in expand_to_path() passes the wrong string length. Let's fix that. The loop in expand_to_path() searches the name-hash for each sub-directory prefix in the provided pathname. That is, by searching for "dir1/" then "dir1/dir2/" then "dir1/dir2/dir3/" and so on until it finds a cache-entry representing a sparse directory. The code creates "strbuf path_mutable" to contain the working pathname and modifies the buffer in-place by temporarily replacing the character following each successive "/" with NUL for the duration of the call to index_file_exists(). It does not update the strbuf.len during this substitution. Pass the patched length of the prefix path instead. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8787a9 commit 156e28b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sparse-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ void expand_to_path(struct index_state *istate,
326326
replace++;
327327
temp = *replace;
328328
*replace = '\0';
329+
substr_len = replace - path_mutable.buf;
329330
if (index_file_exists(istate, path_mutable.buf,
330-
path_mutable.len, icase)) {
331+
substr_len, icase)) {
331332
/*
332333
* We found a parent directory in the name-hash
333334
* hashtable, because only sparse directory entries
@@ -340,7 +341,6 @@ void expand_to_path(struct index_state *istate,
340341
}
341342

342343
*replace = temp;
343-
substr_len = replace - path_mutable.buf;
344344
}
345345

346346
cleanup:

0 commit comments

Comments
 (0)