aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-31 01:29:20 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-31 01:29:20 +0100
commit270ed4f02578a85d4c98ab80c78f6203066d0055 (patch)
treea89a8327e3027476d4bd1bfd3172a4329b44c3a5
parent0c62349440c8231705d41a389d198434e45acb27 (diff)
Create a copy of argv in cbsinit()
-rw-r--r--cbs.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/cbs.h b/cbs.h
index 47f0031..1c3b833 100644
--- a/cbs.h
+++ b/cbs.h
@@ -367,7 +367,14 @@ void
cbsinit(int argc, char **argv)
{
_cbs_argc = argc;
- _cbs_argv = argv;
+ _cbs_argv = bufalloc(NULL, argc, sizeof(char *));
+ for (int i = 0; i < argc; i++) {
+ if (!(_cbs_argv[i] = strdup(argv[i]))) {
+ /* We might not have set _cbs_argv[0] yet, so we can’t use die() */
+ fprintf(stderr, "%s: strdup: %s\n", *argv, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
}
static size_t