]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: fix clang warning when building w/o libcap
authorIgor Galić <igor.galic@automatic-server.com>
Wed, 14 Mar 2018 15:53:24 +0000 (16:53 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 23 Aug 2018 20:44:21 +0000 (22:44 +0200)
when compiling lxc with clang-5.0 parse_cap()'s main loop will produce a
warning about a tautological comparision (#2215).

By moving the result of computation into a variable (end) this is no
longer a constant expression. clang-5.0 does not do dataflow analysis at
this point, so it is, to quote someone from #llvm, "morally equivalent"
to casting `(int)i`.

in addition, we also clean up the #if HAVE_LIBCAP to no longer need
its #else branch!

Signed-off-by: Igor Galić <igor.galic@automatic-server.com>
src/lxc/conf.c

index c7bf596d21f881774a0146517c7396f3f6354ff4..cf3c8a7ceafebb75e69cd13876ef5ecb004405cd 100644 (file)
@@ -194,8 +194,8 @@ static struct mount_opt propagation_opt[] = {
        { NULL,            0, 0                    },
 };
 
-#if HAVE_LIBCAP
 static struct caps_opt caps_opt[] = {
+#if HAVE_LIBCAP
        { "chown",             CAP_CHOWN             },
        { "dac_override",      CAP_DAC_OVERRIDE      },
        { "dac_read_search",   CAP_DAC_READ_SEARCH   },
@@ -246,10 +246,8 @@ static struct caps_opt caps_opt[] = {
 #ifdef CAP_BLOCK_SUSPEND
        { "block_suspend",     CAP_BLOCK_SUSPEND     },
 #endif
-};
-#else
-static struct caps_opt caps_opt[] = {};
 #endif
+};
 
 static int run_buffer(char *buffer)
 {
@@ -2273,11 +2271,12 @@ static int parse_cap(const char *cap)
        char *ptr = NULL;
        size_t i;
        int capid = -1;
+       size_t end = sizeof(caps_opt)/sizeof(caps_opt[0]);
 
        if (!strcmp(cap, "none"))
                return -2;
 
-       for (i = 0; i < sizeof(caps_opt)/sizeof(caps_opt[0]); i++) {
+       for (i = 0; i < end; i++) {
 
                if (strcmp(cap, caps_opt[i].name))
                        continue;