diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-12-31 01:29:20 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-12-31 01:29:20 +0100 |
commit | 270ed4f02578a85d4c98ab80c78f6203066d0055 (patch) | |
tree | a89a8327e3027476d4bd1bfd3172a4329b44c3a5 | |
parent | 0c62349440c8231705d41a389d198434e45acb27 (diff) |
Create a copy of argv in cbsinit()
-rw-r--r-- | cbs.h | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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 |