]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
compiler: -Wshadow hardening 2823/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 5 Feb 2019 19:56:08 +0000 (20:56 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 5 Feb 2019 21:36:31 +0000 (22:36 +0100)
Warn whenever a local variable or type declaration shadows another
variable, parameter, type, class member (in C++), or instance variable
(in Objective-C) or whenever a built-in function is shadowed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
15 files changed:
src/lxc/attach.c
src/lxc/cmd/lxc_user_nic.c
src/lxc/conf.c
src/lxc/criu.c
src/lxc/log.h
src/lxc/lxccontainer.c
src/lxc/network.c
src/lxc/storage/overlay.c
src/lxc/storage/storage.c
src/lxc/storage/zfs.c
src/lxc/tools/lxc_info.c
src/lxc/tools/lxc_ls.c
src/lxc/tools/lxc_unshare.c
src/tests/share_ns.c
src/tests/state_server.c

index 117e3778fab182de29b24cf7c5754a149d973649..df9dda02eb45755ea07eec0951c8fa67bd1d67cf 100644 (file)
@@ -1351,10 +1351,10 @@ int lxc_attach(const char *name, const char *lxcpath,
                if ((options->namespaces & CLONE_NEWNS) &&
                    (options->attach_flags & LXC_ATTACH_LSM) &&
                    init_ctx->lsm_label) {
-                       int ret = -1;
                        int labelfd;
                        bool on_exec;
 
+                       ret = -1;
                        on_exec = options->attach_flags & LXC_ATTACH_LSM_EXEC ? true : false;
                        labelfd = lsm_process_label_fd_get(attached_pid, on_exec);
                        if (labelfd < 0)
index 12c3d83c71ad1b836f31e141bf1b97df3679d2d6..bd60228aaf9d00ca903e2f4b8bc1d3c1c9e28d07 100644 (file)
@@ -1250,7 +1250,6 @@ int main(int argc, char *argv[])
        free(me);
 
        if (request == LXC_USERNIC_DELETE) {
-               int ret;
                struct alloted_s *it;
                bool found_nicname = false;
 
index be2852f2700e58f57deb118cec73b74890a62224..57144c97227016d3c38b917f6c367bb2098ae068 100644 (file)
@@ -3377,7 +3377,6 @@ again:
        }
 
        while (getline(&line, &len, f) != -1) {
-               int ret;
                char *opts, *target;
 
                target = get_field(line, 4);
index d1807c9390b6d5e1b26acc7f8b5254aa69a4a4f2..7fd4d338a835eaca126738de949e85904f8d9725 100644 (file)
@@ -1070,7 +1070,6 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
                rmdir(rootfs->mount);
                goto out_fini_handler;
        } else {
-               int ret;
                char title[2048];
 
                close(pipes[1]);
@@ -1299,7 +1298,6 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
                int status;
                ssize_t n;
                char buf[4096];
-               bool ret;
 
                close(criuout[1]);
 
index 008df7a734d66cf53e547debefb0c4ef1a18267f..3b7557edbdff920d62a899901bcd85bc29c14390 100644 (file)
@@ -342,9 +342,9 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
                        char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"};   \
                        char *ptr = NULL;                                                \
                        {                                                                \
-                               int saved_errno = errno;                                 \
+                               int __saved_errno = errno;                               \
                                ptr = strerror_r(errno, errno_buf, sizeof(errno_buf));   \
-                               errno = saved_errno;                                     \
+                               errno = __saved_errno;                                   \
                                if (!ptr)                                                \
                                        ptr = errno_buf;                                 \
                        }
@@ -353,9 +353,9 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
                        char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"};   \
                        char *ptr = errno_buf;                                           \
                        {                                                                \
-                               int saved_errno = errno;                                 \
+                               int __saved_errno = errno;                               \
                                (void)strerror_r(errno, errno_buf, sizeof(errno_buf));   \
-                               errno = saved_errno;                                     \
+                               errno = __saved_errno;                                   \
                        }
        #endif
 #elif ENFORCE_THREAD_SAFETY
index 7c826a9fd0a9da5d3a646bf1fd66801c87ac135f..06384f0692335c1e4e3414d5c57900b6653a91da 100644 (file)
@@ -1041,7 +1041,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
         * right PID.
         */
        if (c->pidfile) {
-               int ret, w;
+               int w;
                char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
                w = snprintf(pidstr, sizeof(pidstr), "%d", lxc_raw_getpid());
@@ -2439,8 +2439,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
        if (pid == 0) {
                ssize_t nbytes;
                char addressOutputBuffer[INET6_ADDRSTRLEN];
-               int ret = 1;
-               char *address = NULL;
+               char *address_ptr = NULL;
                void *tempAddrPtr = NULL;
                struct netns_ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
 
@@ -2489,16 +2488,16 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
                        else if (!interface && strcmp("lo", tempIfAddr->ifa_name) == 0)
                                continue;
 
-                       address = (char *)inet_ntop(tempIfAddr->ifa_addr->sa_family,
+                       address_ptr = (char *)inet_ntop(tempIfAddr->ifa_addr->sa_family,
                                                    tempAddrPtr, addressOutputBuffer,
                                                    sizeof(addressOutputBuffer));
-                       if (!address)
+                       if (!address_ptr)
                                continue;
 
-                       nbytes = lxc_write_nointr(pipefd[1], address, INET6_ADDRSTRLEN);
+                       nbytes = lxc_write_nointr(pipefd[1], address_ptr, INET6_ADDRSTRLEN);
                        if (nbytes != INET6_ADDRSTRLEN) {
                                SYSERROR("Failed to send ipv6 address \"%s\"",
-                                        address);
+                                        address_ptr);
                                goto out;
                        }
 
index 499ddff6e8f32d33873b6970775ca4113b3f6bf9..ec75b0c280ca02379e2d6199abde406a5e32ff0f 100644 (file)
@@ -2116,8 +2116,6 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
        }
 
        if (child == 0) {
-               int ret;
-               size_t retlen;
                char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
                close(pipefd[0]);
@@ -2280,7 +2278,6 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
 
        if (child == 0) {
                char *hostveth;
-               int ret;
 
                close(pipefd[0]);
 
@@ -2925,8 +2922,6 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
 
        /* set the network device up */
        if (netdev->flags & IFF_UP) {
-               int err;
-
                err = lxc_netdev_up(current_ifname);
                if (err) {
                        errno = -err;
index 01546b1bf1a196953a161d0e230d6b52faac6a0f..1a593b340dd2ab7f0b003cb2ceba63c3056749b1 100644 (file)
@@ -86,7 +86,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
        if (strcmp(orig->type, "dir") == 0) {
                char *delta, *lastslash;
                char *work;
-               int ret, len, lastslashidx;
+               int len, lastslashidx;
 
                /* If we have "/var/lib/lxc/c2/rootfs" then delta will be
                 * "/var/lib/lxc/c2/delta0".
@@ -194,7 +194,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
                char *clean_old_path, *clean_new_path;
                char *lastslash, *ndelta, *nsrc, *odelta, *osrc, *s1, *s2, *s3,
                    *work;
-               int ret, lastslashidx;
+               int lastslashidx;
                size_t len, name_len;
 
                osrc = strdup(orig->src);
index c4f4c2ea3024c6c0d1e5528be2845c35445180a9..837e8cabeebb1fdb3a3e518eafba375be7ede753 100644 (file)
@@ -355,7 +355,6 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
        }
 
        if (!orig->dest) {
-               int ret;
                size_t len;
                struct stat sb;
 
index ba104da54239aeb3da59bca985f21a0924ea2474..0a804ad19c528c22d00e7458e254e5b5e8285a2a 100644 (file)
@@ -468,7 +468,6 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
 
        orig_src = lxc_storage_get_path(orig->src, orig->type);
        if (!strcmp(orig->type, "zfs")) {
-               size_t len;
                if (*orig_src == '/') {
                        bool found;
 
@@ -594,8 +593,6 @@ int zfs_destroy(struct lxc_storage *orig)
         * "<lxcpath>/<lxcname>/rootfs" is given.
         */
        if (*src == '/') {
-               char *tmp;
-
                found = zfs_list_entry(src, cmd_output, sizeof(cmd_output));
                if (!found) {
                        ERROR("Failed to find zfs entry \"%s\"", orig->src);
index 138a3060ba52a3e40d9f1db7a5cace6b8533689c..1aae1c6f2e387e3691ddc600c5c1da1a0ccd1d15 100644 (file)
@@ -274,28 +274,28 @@ static void print_stats(struct lxc_container *c)
        }
 }
 
-static void print_info_msg_int(const char *key, int value)
+static void print_info_msg_int(const char *k, int value)
 {
        if (humanize)
-               printf("%-15s %d\n", key, value);
+               printf("%-15s %d\n", k, value);
        else {
                if (filter_count == 1)
                        printf("%d\n", value);
                else
-                       printf("%-15s %d\n", key, value);
+                       printf("%-15s %d\n", k, value);
        }
        fflush(stdout);
 }
 
-static void print_info_msg_str(const char *key, const char *value)
+static void print_info_msg_str(const char *k, const char *value)
 {
        if (humanize)
-               printf("%-15s %s\n", key, value);
+               printf("%-15s %s\n", k, value);
        else {
                if (filter_count == 1)
                        printf("%s\n", value);
                else
-                       printf("%-15s %s\n", key, value);
+                       printf("%-15s %s\n", k, value);
        }
        fflush(stdout);
 }
index cb3eb1e52de19dbb5893d1fd16c4b1205a6d5405..8f7a5a2fc885526e7cb1b5d6c3ba9b9cfbd6f55a 100644 (file)
@@ -512,8 +512,6 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
                                l->unprivileged = !(val == NULL);
                                free(val);
                        } else {
-                               int ret;
-
                                ret = c->get_config_item(c, "lxc.idmap", NULL, 0);
                                l->unprivileged = !(ret == 0);
                        }
index a86d12b3c776e67be78b3534fb75b17052df601c..f9a6969f8970b17da7ea79f6bbf91b3adc788106 100644 (file)
@@ -64,7 +64,7 @@ struct start_arg {
 static int my_parser(struct lxc_arguments *args, int c, char *arg);
 static inline int sethostname_including_android(const char *name, size_t len);
 static int get_namespace_flags(char *namespaces);
-static bool lookup_user(const char *optarg, uid_t *uid);
+static bool lookup_user(const char *oparg, uid_t *uid);
 static int mount_fs(const char *source, const char *target, const char *type);
 static void lxc_setup_fs(void);
 static int do_start(void *arg);
@@ -180,7 +180,7 @@ static int get_namespace_flags(char *namespaces)
        return flags;
 }
 
-static bool lookup_user(const char *optarg, uid_t *uid)
+static bool lookup_user(const char *oparg, uid_t *uid)
 {
        char name[PATH_MAX];
        struct passwd pwent;
@@ -189,7 +189,7 @@ static bool lookup_user(const char *optarg, uid_t *uid)
        size_t bufsize;
        int ret;
 
-       if (!optarg || (optarg[0] == '\0'))
+       if (!oparg || (oparg[0] == '\0'))
                return false;
 
        bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
@@ -200,9 +200,9 @@ static bool lookup_user(const char *optarg, uid_t *uid)
        if (!buf)
                return false;
 
-       if (sscanf(optarg, "%u", uid) < 1) {
+       if (sscanf(oparg, "%u", uid) < 1) {
                /* not a uid -- perhaps a username */
-               if (sscanf(optarg, "%s", name) < 1) {
+               if (sscanf(oparg, "%s", name) < 1) {
                        free(buf);
                        return false;
                }
@@ -431,24 +431,24 @@ int main(int argc, char *argv[])
        if (lxc_list_len(&ifnames) > 0) {
                struct lxc_list *iterator;
                char* ifname;
-               pid_t pid;
+               pid_t lpid;
 
                lxc_list_for_each(iterator, &ifnames) {
                        ifname = iterator->elem;
                        if (!ifname)
                                continue;
 
-                       pid = fork();
-                       if (pid < 0) {
+                       lpid = fork();
+                       if (lpid < 0) {
                                SYSERROR("Failed to move network device \"%s\" to network namespace",
                                         ifname);
                                continue;
                        }
 
-                       if (pid == 0) {
+                       if (lpid == 0) {
                                char buf[256];
 
-                               ret = snprintf(buf, 256, "%d", pid);
+                               ret = snprintf(buf, 256, "%d", lpid);
                                if (ret < 0 || ret >= 256)
                                        _exit(EXIT_FAILURE);
 
@@ -456,9 +456,9 @@ int main(int argc, char *argv[])
                                _exit(EXIT_FAILURE);
                        }
 
-                       if (wait_for_pid(pid) != 0)
+                       if (wait_for_pid(lpid) != 0)
                                SYSERROR("Could not move interface \"%s\" into container %d",
-                                        ifname, pid);
+                                        ifname, lpid);
                }
 
                free_ifname_list();
index d65aef85a7d4456752788113327b4dfb015ba62d..3c74a165e19cc537907bd9a452808dc7745e4030 100644 (file)
@@ -269,8 +269,6 @@ int main(int argc, char *argv[])
                lxc_debug("Starting namespace sharing test iteration %d\n", j);
 
                for (i = 0; i < 10; i++) {
-                       int ret;
-
                        args[i].thread_id = i;
                        args[i].success = false;
                        args[i].init_pid = init_pid;
@@ -283,8 +281,6 @@ int main(int argc, char *argv[])
                }
 
                for (i = 0; i < 10; i++) {
-                       int ret;
-
                        ret = pthread_join(threads[i], NULL);
                        if (ret != 0)
                                goto on_error_stop;
index d24ba8b3db5da1c74f2a3aa85c4db756f249a814..bb64a87cba37b2a32ec44c5c6f351bd2c862dcb8 100644 (file)
@@ -108,8 +108,6 @@ int main(int argc, char *argv[])
                sleep(5);
 
                for (i = 0; i < 10; i++) {
-                       int ret;
-
                        args[i].thread_id = i;
                        args[i].c = c;
                        args[i].timeout = -1;
@@ -123,8 +121,6 @@ int main(int argc, char *argv[])
                }
 
                for (i = 0; i < 10; i++) {
-                       int ret;
-
                        ret = pthread_join(threads[i], NULL);
                        if (ret != 0)
                                goto on_error_stop;