compiler: -Wshadow hardening

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