aboutsummaryrefslogtreecommitdiffstats
path: root/strvec.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-12-04 10:14:38 +0900
committerJunio C Hamano <gitster@pobox.com>2024-12-04 10:14:40 +0900
commita5dd262a7504fc816d0aad7c7dc7eb73cb0adf82 (patch)
treecac04682f84642083987a06d1c2ae6ebcf8e4a38 /strvec.c
parentMerge branch 'ps/gc-stale-lock-warning' (diff)
parentt: remove TEST_PASSES_SANITIZE_LEAK annotations (diff)
downloadgit-a5dd262a7504fc816d0aad7c7dc7eb73cb0adf82.tar.gz
git-a5dd262a7504fc816d0aad7c7dc7eb73cb0adf82.zip
Merge branch 'ps/leakfixes-part-10'
Leakfixes. * ps/leakfixes-part-10: (27 commits) t: remove TEST_PASSES_SANITIZE_LEAK annotations test-lib: unconditionally enable leak checking t: remove unneeded !SANITIZE_LEAK prerequisites t: mark some tests as leak free t5601: work around leak sanitizer issue git-compat-util: drop now-unused `UNLEAK()` macro global: drop `UNLEAK()` annotation t/helper: fix leaking commit graph in "read-graph" subcommand builtin/branch: fix leaking sorting options builtin/init-db: fix leaking directory paths builtin/help: fix leaks in `check_git_cmd()` help: fix leaking return value from `help_unknown_cmd()` help: fix leaking `struct cmdnames` help: refactor to not use globals for reading config builtin/sparse-checkout: fix leaking sanitized patterns split-index: fix memory leak in `move_cache_to_base_index()` git: refactor builtin handling to use a `struct strvec` git: refactor alias handling to use a `struct strvec` strvec: introduce new `strvec_splice()` function line-log: fix leak when rewriting commit parents ...
Diffstat (limited to 'strvec.c')
-rw-r--r--strvec.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/strvec.c b/strvec.c
index f712070f57..d1cf4e2496 100644
--- a/strvec.c
+++ b/strvec.c
@@ -56,6 +56,25 @@ void strvec_pushv(struct strvec *array, const char **items)
strvec_push(array, *items);
}
+void strvec_splice(struct strvec *array, size_t idx, size_t len,
+ const char **replacement, size_t replacement_len)
+{
+ if (idx + len > array->nr)
+ BUG("range outside of array boundary");
+ if (replacement_len > len)
+ ALLOC_GROW(array->v, array->nr + (replacement_len - len) + 1,
+ array->alloc);
+ for (size_t i = 0; i < len; i++)
+ free((char *)array->v[idx + i]);
+ if (replacement_len != len) {
+ memmove(array->v + idx + replacement_len, array->v + idx + len,
+ (array->nr - idx - len + 1) * sizeof(char *));
+ array->nr += (replacement_len - len);
+ }
+ for (size_t i = 0; i < replacement_len; i++)
+ array->v[idx + i] = xstrdup(replacement[i]);
+}
+
const char *strvec_replace(struct strvec *array, size_t idx, const char *replacement)
{
char *to_free;