Skip to content

Commit 93ea118

Browse files
rscharfegitster
authored andcommitted
cache-tree: fix strbuf growth in prime_cache_tree_rec()
Use size_t to store the original length of the strbuf tree_len, as that's the correct type. Don't double the allocated size of the strbuf when adding a subdirectory name. And the chance of the trailing slash fitting in the slack left by strbuf_add() is very high, so stop pre-growing the strbuf at all. Suggested-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 844ede3 commit 93ea118

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

cache-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static void prime_cache_tree_rec(struct repository *r,
760760
struct tree_desc desc;
761761
struct name_entry entry;
762762
int cnt;
763-
int base_path_len = tree_path->len;
763+
size_t base_path_len = tree_path->len;
764764

765765
oidcpy(&it->oid, &tree->object.oid);
766766

@@ -785,7 +785,6 @@ static void prime_cache_tree_rec(struct repository *r,
785785
*/
786786
if (r->index->sparse_index) {
787787
strbuf_setlen(tree_path, base_path_len);
788-
strbuf_grow(tree_path, base_path_len + entry.pathlen + 1);
789788
strbuf_add(tree_path, entry.path, entry.pathlen);
790789
strbuf_addch(tree_path, '/');
791790
}

0 commit comments

Comments
 (0)