[lxc-devel] [PATCH] Initialize a pointer in split_init_cmd() to avoid gcc warnings

Leonid Isaev leonid.isaev at jila.colorado.edu
Thu Apr 21 19:20:39 UTC 2016


gcc -Wall warns about uninitialized variables (-Wmaybe-uninitialized), and
-Werror makes it fatal. This change allows the build to succeed by NULL'ifying
the pointer passed to strtok_r().

Note that strtok_r(3) anyway ignores a non-NULL arg3 pointer on the 1st call
with non-NULL arg1 string.

Signed-off-by: Leonid Isaev <leonid.isaev at jila.colorado.edu>
---
 src/lxc/lxccontainer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 9f12ca2..50cfc69 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -670,7 +670,7 @@ static char **split_init_cmd(const char *incmd)
 {
        size_t len;
        int nargs = 0;
-       char *copy, *p, *saveptr;
+       char *copy, *p, *saveptr = NULL;
        char **argv;
 
        if (!incmd)
-- 
2.8.0

-- 
Leonid Isaev
GPG fingerprints: DA92 034D B4A8 EC51 7EA6  20DF 9291 EE8A 043C B8C4
                  C0DF 20D0 C075 C3F1 E1BE  775A A7AE F6CB 164B 5A6D


More information about the lxc-devel mailing list