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 <jeffhostetler@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Feb 2, 2024 at 18:04 UTC 156e28b36d424a26b4548de636fa548b14defa71
1 file changed +2 -2
sparse-index.c
+2 -2
@@ -326,8 +326,9 @@ void expand_to_path(struct index_state *istate,
326 replace++;
327 temp = *replace;
328 *replace = '\0';
329 + substr_len = replace - path_mutable.buf;
330 if (index_file_exists(istate, path_mutable.buf,
330 - path_mutable.len, icase)) {
331 + substr_len, icase)) {
332 /*
333 * We found a parent directory in the name-hash
334 * hashtable, because only sparse directory entries
@@ -340,7 +341,6 @@ void expand_to_path(struct index_state *istate,
341 }
342
343 *replace = temp;
343 - substr_len = replace - path_mutable.buf;
344 }
345
346 cleanup: