aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomas.voss@humanwave.nl> 2024-01-18 16:52:45 +0100
committerThomas Voss <thomas.voss@humanwave.nl> 2024-01-18 16:52:45 +0100
commite8f63ab90c10358a7e14121e66fa29d269ad1d16 (patch)
treecc8f6d7aefddad6455169a8756ace7897da2386d
parentd807ba646948eb178ee92c684578dd96e94873fd (diff)
Append to sv instead of overwriting it
-rw-r--r--cbs.h26
1 files changed, 12 insertions, 14 deletions
diff --git a/cbs.h b/cbs.h
index b94f7b7..b807742 100644
--- a/cbs.h
+++ b/cbs.h
@@ -614,21 +614,19 @@ env_or_defaultv(struct strv *sv, const char *s, char **p, size_t n)
die("wordexp");
}
- sv->buf = bufalloc(NULL, we.we_wordc, sizeof(*sv->buf));
- for (size_t i = 0; i < we.we_wordc; i++) {
- if (!(sv->buf[i] = strdup(we.we_wordv[i])))
- die("strdup");
- }
- sv->len = we.we_wordc;
- wordfree(&we);
- } else {
- sv->buf = bufalloc(NULL, n, sizeof(*sv->buf));
- for (size_t i = 0; i < n; i++) {
- if (!(sv->buf[i] = strdup(p[i])))
- die("strdup");
- }
- sv->len = n;
+ p = we.we_wordv;
+ n = we.we_wordc;
+ }
+
+ sv->buf = bufalloc(sv->buf, sv->len + n, sizeof(*sv->buf));
+ for (size_t i = 0; i < n; i++) {
+ if (!(sv->buf[sv->len + i] = strdup(p[i])))
+ die("strdup");
}
+ sv->len += n;
+
+ if (ev && *ev)
+ wordfree(&we);
}
bool