]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1440389
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Oct 2018 09:59:48 +0000 (11:59 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 22 Oct 2018 14:48:37 +0000 (16:48 +0200)
Logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/include/netns_ifaddrs.c

index fc0ffc167499993ee929a7033f9e84cada1b4f6d..1c8b92b66bef8370fabecf1b5f8591abc3b4522a 100644 (file)
@@ -373,12 +373,7 @@ static int __ifaddrs_netlink_recv(int fd, unsigned int seq, int type, int af,
                                            struct nlmsghdr *h),
                                  void *ctx)
 {
-       char getlink_buf[__NETLINK_ALIGN(sizeof(struct nlmsghdr)) +
-                        __NETLINK_ALIGN(sizeof(struct ifinfomsg)) +
-                        __NETLINK_ALIGN(1024)];
-       char getaddr_buf[__NETLINK_ALIGN(sizeof(struct nlmsghdr)) +
-                        __NETLINK_ALIGN(sizeof(struct ifaddrmsg)) +
-                        __NETLINK_ALIGN(1024)];
+       int r, property, ret;
        char *buf;
        struct nlmsghdr *hdr;
        struct ifinfomsg *ifi_msg;
@@ -391,47 +386,43 @@ static int __ifaddrs_netlink_recv(int fd, unsigned int seq, int type, int af,
                } req;
                struct nlmsghdr reply;
        } u;
-       int r, property, ret;
-
-       if (type == RTM_GETLINK)
-               buf = getlink_buf;
-       else if (type == RTM_GETADDR)
-               buf = getaddr_buf;
-       else
-               return -1;
-
-       memset(buf, 0, sizeof(*buf));
+       char getlink_buf[__NETLINK_ALIGN(sizeof(struct nlmsghdr)) +
+                        __NETLINK_ALIGN(sizeof(struct ifinfomsg)) +
+                        __NETLINK_ALIGN(1024)] = {0};
+       char getaddr_buf[__NETLINK_ALIGN(sizeof(struct nlmsghdr)) +
+                        __NETLINK_ALIGN(sizeof(struct ifaddrmsg)) +
+                        __NETLINK_ALIGN(1024)] = {0};
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wcast-align"
-       hdr = (struct nlmsghdr *)buf;
-       if (type == RTM_GETLINK)
+       if (type == RTM_GETLINK) {
+               buf = getlink_buf;
+               hdr = (struct nlmsghdr *)buf;
+               hdr->nlmsg_len = NLMSG_LENGTH(sizeof(*ifi_msg));
+
                ifi_msg = (struct ifinfomsg *)__NLMSG_DATA(hdr);
-       else
-               ifa_msg = (struct ifaddrmsg *)__NLMSG_DATA(hdr);
+               ifi_msg->ifi_family = af;
 
-       if (type == RTM_GETLINK)
-               hdr->nlmsg_len = NLMSG_LENGTH(sizeof(*ifi_msg));
-       else
+               property = IFLA_TARGET_NETNSID;
+       } else if (type == RTM_GETADDR) {
+               buf = getaddr_buf;
+               hdr = (struct nlmsghdr *)buf;
                hdr->nlmsg_len = NLMSG_LENGTH(sizeof(*ifa_msg));
+
+               ifa_msg = (struct ifaddrmsg *)__NLMSG_DATA(hdr);
+               ifa_msg->ifa_family = af;
+
+               property = IFA_TARGET_NETNSID;
+       } else {
+               errno = EINVAL;
+               return -1;
+       }
 #pragma GCC diagnostic pop
 
        hdr->nlmsg_type = type;
        hdr->nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
        hdr->nlmsg_pid = 0;
        hdr->nlmsg_seq = seq;
-       if (type == RTM_GETLINK)
-               ifi_msg->ifi_family = af;
-       else
-               ifa_msg->ifa_family = af;
-
-       errno = EINVAL;
-       if (type == RTM_GETLINK)
-               property = IFLA_TARGET_NETNSID;
-       else if (type == RTM_GETADDR)
-               property = IFA_TARGET_NETNSID;
-       else
-               return -1;
 
        if (netns_id >= 0)
                addattr(hdr, 1024, property, &netns_id, sizeof(netns_id));