From: Christian Brauner Date: Sat, 24 Feb 2018 14:24:29 +0000 (+0100) Subject: lxccontainer: split_init_cmd() X-Git-Tag: lxc-3.0.0.beta1~15^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75bd13abd391f08398946785856f4f89554cef6b;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 fb5f5d05c..b7b87972e 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -727,9 +727,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; @@ -737,20 +738,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; }