From: Christian Brauner Date: Sat, 24 Feb 2018 14:24:29 +0000 (+0100) Subject: lxccontainer: split_init_cmd() X-Git-Tag: lxc-2.0.10~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a65270cc2f2c5f4af1823348d75f66923f7486e;p=thirdparty%2Flxc.git lxccontainer: split_init_cmd() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index af693ca4d..7d8e4103a 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -700,9 +700,10 @@ static void push_arg(char ***argp, char *arg, int *nargs) static char **split_init_cmd(const char *incmd) { size_t len; - int nargs = 0; - char *copy, *p, *saveptr = NULL; + char *copy, *p; char **argv; + int nargs = 0; + char *saveptr = NULL; if (!incmd) return NULL; @@ -710,20 +711,21 @@ static char **split_init_cmd(const char *incmd) len = strlen(incmd) + 1; copy = alloca(len); strncpy(copy, incmd, len); - copy[len-1] = '\0'; + copy[len - 1] = '\0'; do { argv = malloc(sizeof(char *)); } while (!argv); + argv[0] = NULL; - for (p = strtok_r(copy, " ", &saveptr); p != NULL; - p = strtok_r(NULL, " ", &saveptr)) + for (; (p = strtok_r(copy, " ", &saveptr)); copy = NULL) push_arg(&argv, p, &nargs); if (nargs == 0) { free(argv); return NULL; } + return argv; }