[PATCH 1/2] virarptable: Avoid cast align warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have to use VIR_WARNINGS_NO_CAST_ALIGN to avoid clang warning
about increased required alignment caused by some netlink macros.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virarptable.c | 100 ++++++++++++++++++++++++-------------------------
 1 file changed, 50 insertions(+), 50 deletions(-)

diff --git a/src/util/virarptable.c b/src/util/virarptable.c
index 8d9ab5fdc8..3819435d38 100644
--- a/src/util/virarptable.c
+++ b/src/util/virarptable.c
@@ -51,10 +51,11 @@ static int
 parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
 {
     memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
-    while (RTA_OK(rta, len)) {
+    VIR_WARNINGS_NO_CAST_ALIGN
+    for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
+        VIR_WARNINGS_RESET
         if ((rta->rta_type <= max) && (!tb[rta->rta_type]))
             tb[rta->rta_type] = rta;
-        rta = RTA_NEXT(rta, len);
     }
 
     if (len)
@@ -82,73 +83,72 @@ virArpTablePtr virArpTableGet(void)
 
     nh = (struct nlmsghdr*)nlData;
 
-    while (NLMSG_OK(nh, msglen)) {
+    VIR_WARNINGS_NO_CAST_ALIGN
+    for(; NLMSG_OK(nh, msglen); nh = NLMSG_NEXT(nh, msglen)) {
+        VIR_WARNINGS_RESET
         struct ndmsg *r = NLMSG_DATA(nh);
         int len = nh->nlmsg_len;
         void *addr;
 
-      if ((len -= NLMSG_LENGTH(sizeof(*nh))) < 0) {
-          virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                         _("wrong nlmsg len"));
-          goto cleanup;
-      }
+        if ((len -= NLMSG_LENGTH(sizeof(*nh))) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("wrong nlmsg len"));
+            goto cleanup;
+        }
 
-      if (r->ndm_family && (r->ndm_family != AF_INET))
-          goto next_nlmsg;
+        if (r->ndm_family && (r->ndm_family != AF_INET))
+            continue;
 
-      /* catch stale and reachalbe arp entry only */
-      if (r->ndm_state &&
-          (!(r->ndm_state == NUD_STALE || r->ndm_state == NUD_REACHABLE))) {
-          nh = NLMSG_NEXT(nh, msglen);
-          continue;
-      }
+        /* catch stale and reachalbe arp entry only */
+        if (r->ndm_state &&
+            (!(r->ndm_state == NUD_STALE || r->ndm_state == NUD_REACHABLE)))
+            continue;
 
-      if (nh->nlmsg_type == NLMSG_DONE)
-          goto end_of_netlink_messages;
+        if (nh->nlmsg_type == NLMSG_DONE)
+            goto end_of_netlink_messages;
 
-      parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
-                   nh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
+        VIR_WARNINGS_NO_CAST_ALIGN
+        parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
+                     nh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
+        VIR_WARNINGS_RESET
 
-      if (tb[NDA_DST] == NULL || tb[NDA_LLADDR] == NULL)
-          goto next_nlmsg;
+        if (tb[NDA_DST] == NULL || tb[NDA_LLADDR] == NULL)
+            continue;
 
-      if (tb[NDA_DST]) {
-          virSocketAddr virAddr;
-          if (VIR_REALLOC_N(table->t, num + 1) < 0)
-              goto cleanup;
+        if (tb[NDA_DST]) {
+            virSocketAddr virAddr;
+            if (VIR_REALLOC_N(table->t, num + 1) < 0)
+                goto cleanup;
 
-          table->n = num + 1;
+            table->n = num + 1;
 
-          addr = RTA_DATA(tb[NDA_DST]);
-          bzero(&virAddr, sizeof(virAddr));
-          virAddr.len = sizeof(virAddr.data.inet4);
-          virAddr.data.inet4.sin_family = AF_INET;
-          virAddr.data.inet4.sin_addr = *(struct in_addr *)addr;
-          ipstr = virSocketAddrFormat(&virAddr);
+            addr = RTA_DATA(tb[NDA_DST]);
+            bzero(&virAddr, sizeof(virAddr));
+            virAddr.len = sizeof(virAddr.data.inet4);
+            virAddr.data.inet4.sin_family = AF_INET;
+            virAddr.data.inet4.sin_addr = *(struct in_addr *)addr;
+            ipstr = virSocketAddrFormat(&virAddr);
 
-          if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0)
-              goto cleanup;
+            if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0)
+                goto cleanup;
 
-          VIR_FREE(ipstr);
-      }
+            VIR_FREE(ipstr);
+        }
 
-      if (tb[NDA_LLADDR]) {
-          virMacAddr macaddr;
-          char ifmac[VIR_MAC_STRING_BUFLEN];
+        if (tb[NDA_LLADDR]) {
+            virMacAddr macaddr;
+            char ifmac[VIR_MAC_STRING_BUFLEN];
 
-          addr = RTA_DATA(tb[NDA_LLADDR]);
-          memcpy(macaddr.addr, addr, VIR_MAC_BUFLEN);
+            addr = RTA_DATA(tb[NDA_LLADDR]);
+            memcpy(macaddr.addr, addr, VIR_MAC_BUFLEN);
 
-          virMacAddrFormat(&macaddr, ifmac);
+            virMacAddrFormat(&macaddr, ifmac);
 
-          if (VIR_STRDUP(table->t[num].mac, ifmac) < 0)
-              goto cleanup;
+            if (VIR_STRDUP(table->t[num].mac, ifmac) < 0)
+                goto cleanup;
 
-          num++;
-      }
-
- next_nlmsg:
-      nh = NLMSG_NEXT(nh, msglen);
+            num++;
+        }
     }
 
  end_of_netlink_messages:
-- 
2.16.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux