diff options
author | Thomas Voss <thomas.voss@humanwave.nl> | 2024-01-18 16:52:45 +0100 |
---|---|---|
committer | Thomas Voss <thomas.voss@humanwave.nl> | 2024-01-18 16:52:45 +0100 |
commit | e8f63ab90c10358a7e14121e66fa29d269ad1d16 (patch) | |
tree | cc8f6d7aefddad6455169a8756ace7897da2386d | |
parent | d807ba646948eb178ee92c684578dd96e94873fd (diff) |
Append to sv instead of overwriting it
-rw-r--r-- | cbs.h | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -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 |