[lxc-users] Can't compile lxc 2.0.0 with gcc 5.3.0 and -Werror=maybe-unitialized

Serge Hallyn serge.hallyn at ubuntu.com
Thu Apr 21 16:45:57 UTC 2016


Quoting Leonid Isaev (leonid.isaev at jila.colorado.edu):
> Hi,
> 
> 	Commit fd51a89b60d06f1f207196e5fe6e8e8f7bea3beb [support arguments in
> lxc.init_cmd] introduced the function split_init_cmd() in lxccontainer.c.
> Compiling this with gcc 5.3.0 (archlinux) and -Werror on uninitialized
> variables causes a build failure (full error is attached):
> --------------------
> lxccontainer.c: In function ‘split_init_cmd’:
> lxccontainer.c:658:8: error: ‘saveptr’ may be used uninitialized in this
> function [-Werror=maybe-uninitialized]
>    copy = strdup(arg);
>         ^
> lxccontainer.c:673:19: note: ‘saveptr’ was declared here
>   char *copy, *p, *saveptr;
>                    ^
> cc1: all warnings being treated as errors
> Makefile:1948: recipe for target 'liblxc_so-lxccontainer.o' failed
> --------------------
> 
> The above error is fixed with a trivial patch:
> --------------------
> --- a/src/lxc/lxccontainer.c    2016-04-20 19:50:24.169180210 -0600
> +++ b/src/lxc/lxccontainer.c    2016-04-20 19:51:13.705199907 -0600
> @@ -670,7 +670,7 @@
>  {
>         size_t len;
>         int nargs = 0;
> -       char *copy, *p, *saveptr;
> +       char *copy, *p, *saveptr = NULL;
>         char **argv;
>  
>         if (!incmd)
> --------------------
> 
> Would such patch be welcome upstream?

I'm not sure.  I don't like it since the strtok_r manpage specifically
says that saveptr is ignored on the first call with non-NULL arg1.
So setting it to NULL is a little misleading, but otoh gcc isn't
going to dive into the called functions to figure that out, so yeah
we'll probably take the patch.


More information about the lxc-users mailing list