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

Leonid Isaev leonid.isaev at jila.colorado.edu
Thu Apr 21 03:18:13 UTC 2016


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?

Thanks a lot,
L.

-- 
Leonid Isaev
GPG fingerprints: DA92 034D B4A8 EC51 7EA6  20DF 9291 EE8A 043C B8C4
                  C0DF 20D0 C075 C3F1 E1BE  775A A7AE F6CB 164B 5A6D
-------------- next part --------------
gcc -DHAVE_CONFIG_H -I. -I../../src   -D_FORTIFY_SOURCE=2 -fPIC -DPIC
-I../../src -DLXCROOTFSMOUNT=\"/usr/lib/lxc/rootfs\" -DLXCPATH=\"/var/lib/lxc\"
-DLXC_GLOBAL_CONF=\"/etc/lxc/lxc.conf\" -DLXCINITDIR=\"/usr/lib\"
-DLIBEXECDIR=\"/usr/lib\" -DLXCTEMPLATEDIR=\"/usr/share/lxc/templates\"
-DLXCTEMPLATECONFIG=\"/usr/share/lxc/config\" -DLOGPATH=\"/var/log/lxc\"
-DLXC_DEFAULT_CONFIG=\"/etc/lxc/default.conf\"
-DLXC_USERNIC_DB=\"/run/lxc/nics\" -DLXC_USERNIC_CONF=\"/etc/lxc/lxc-usernet\"
-DDEFAULT_CGROUP_PATTERN=\"/lxc/%n\" -DRUNTIME_PATH=\"/run\"
-DSBINDIR=\"/usr/bin\"     -DHAVE_SECCOMP  -pthread  -march=x86-64
-mtune=generic -O1 -pipe -fstack-protector-all -fexceptions
-fno-delete-null-pointer-checks --param=ssp-buffer-size=4 -Wall -Werror -MT
liblxc_so-lxccontainer.o -MD -MP -MF .deps/liblxc_so-lxccontainer.Tpo -c -o
liblxc_so-lxccontainer.o `test -f 'lxccontainer.c' || echo './'`lxccontainer.c
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


More information about the lxc-users mailing list