提交 e57aaa6f 编写于 作者: D Daniel P. Berrange

Disable cast-align warnings in various places

There are a number of places which generate cast alignment
warnings, which are difficult or impossible to address. Use
pragmas to disable the warnings in these few places

conf/nwfilter_conf.c: In function 'virNWFilterRuleDetailsParse':
conf/nwfilter_conf.c:1806:16: warning: cast increases required alignment of target type [-Wcast-align]
         item = (nwItemDesc *)((char *)nwf + att[idx].dataIdx);
conf/nwfilter_conf.c: In function 'virNWFilterRuleDefDetailsFormat':
conf/nwfilter_conf.c:3238:16: warning: cast increases required alignment of target type [-Wcast-align]
         item = (nwItemDesc *)((char *)def + att[i].dataIdx);

storage/storage_backend_mpath.c: In function 'virStorageBackendCreateVols':
storage/storage_backend_mpath.c:247:17: warning: cast increases required alignment of target type [-Wcast-align]
         names = (struct dm_names *)(((char *)names) + next);

nwfilter/nwfilter_dhcpsnoop.c: In function 'virNWFilterSnoopDHCPDecode':
nwfilter/nwfilter_dhcpsnoop.c:994:15: warning: cast increases required alignment of target type [-Wcast-align]
         pip = (struct iphdr *) pep->eh_data;
nwfilter/nwfilter_dhcpsnoop.c:1004:11: warning: cast increases required alignment of target type [-Wcast-align]
     pup = (struct udphdr *) ((char *) pip + (pip->ihl << 2));

nwfilter/nwfilter_learnipaddr.c: In function 'procDHCPOpts':
nwfilter/nwfilter_learnipaddr.c:327:33: warning: cast increases required alignment of target type [-Wcast-align]
                 uint32_t *tmp = (uint32_t *)&dhcpopt->value;
nwfilter/nwfilter_learnipaddr.c: In function 'learnIPAddressThread':
nwfilter/nwfilter_learnipaddr.c:501:43: warning: cast increases required alignment of target type [-Wcast-align]
                     struct iphdr *iphdr = (struct iphdr*)(packet +
nwfilter/nwfilter_learnipaddr.c:538:43: warning: cast increases required alignment of target type [-Wcast-align]
                     struct iphdr *iphdr = (struct iphdr*)(packet +
nwfilter/nwfilter_learnipaddr.c:544:48: warning: cast increases required alignment of target type [-Wcast-align]
                         struct udphdr *udphdr= (struct udphdr *)
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 7e6aabc6
...@@ -93,6 +93,7 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ ...@@ -93,6 +93,7 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
if test $lv_cv_gcc_pragma_push_works = no; then if test $lv_cv_gcc_pragma_push_works = no; then
dontwarn="$dontwarn -Wmissing-prototypes" dontwarn="$dontwarn -Wmissing-prototypes"
dontwarn="$dontwarn -Wmissing-declarations" dontwarn="$dontwarn -Wmissing-declarations"
dontwarn="$dontwarn -Wcast-align"
fi fi
dnl Check whether strchr(s, char variable) causes a bogus compile dnl Check whether strchr(s, char variable) causes a bogus compile
......
...@@ -1803,7 +1803,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node, ...@@ -1803,7 +1803,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
while (att[idx].name != NULL) { while (att[idx].name != NULL) {
prop = virXMLPropString(node, att[idx].name); prop = virXMLPropString(node, att[idx].name);
VIR_WARNINGS_NO_CAST_ALIGN
item = (nwItemDesc *)((char *)nwf + att[idx].dataIdx); item = (nwItemDesc *)((char *)nwf + att[idx].dataIdx);
VIR_WARNINGS_RESET
flags = &item->flags; flags = &item->flags;
flags_set = match_flag; flags_set = match_flag;
...@@ -3235,7 +3237,9 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf, ...@@ -3235,7 +3237,9 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf,
nwItemDesc *item; nwItemDesc *item;
while (att[i].name) { while (att[i].name) {
VIR_WARNINGS_NO_CAST_ALIGN
item = (nwItemDesc *)((char *)def + att[i].dataIdx); item = (nwItemDesc *)((char *)def + att[i].dataIdx);
VIR_WARNINGS_RESET
enum virNWFilterEntryItemFlags flags = item->flags; enum virNWFilterEntryItemFlags flags = item->flags;
if ((flags & NWFILTER_ENTRY_ITEM_FLAG_EXISTS)) { if ((flags & NWFILTER_ENTRY_ITEM_FLAG_EXISTS)) {
if (!typeShown) { if (!typeShown) {
......
...@@ -214,6 +214,19 @@ ...@@ -214,6 +214,19 @@
# endif # endif
# endif /* __GNUC__ */ # endif /* __GNUC__ */
# if __GNUC_PREREQ (4, 6)
# define VIR_WARNINGS_NO_CAST_ALIGN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wcast-align\"")
# define VIR_WARNINGS_RESET \
_Pragma ("GCC diagnostic pop")
# else
# define VIR_WARNINGS_NO_CAST_ALIGN
# define VIR_WARNINGS_RESET
# endif
/* /*
* Use this when passing possibly-NULL strings to printf-a-likes. * Use this when passing possibly-NULL strings to printf-a-likes.
*/ */
......
...@@ -991,7 +991,9 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReqPtr req, ...@@ -991,7 +991,9 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReqPtr req,
/* go through the protocol headers */ /* go through the protocol headers */
switch (ntohs(pep->eh_type)) { switch (ntohs(pep->eh_type)) {
case ETHERTYPE_IP: case ETHERTYPE_IP:
VIR_WARNINGS_NO_CAST_ALIGN;
pip = (struct iphdr *) pep->eh_data; pip = (struct iphdr *) pep->eh_data;
VIR_WARNINGS_RESET;
len -= offsetof(virNWFilterSnoopEthHdr, eh_data); len -= offsetof(virNWFilterSnoopEthHdr, eh_data);
break; break;
default: default:
...@@ -1001,7 +1003,9 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReqPtr req, ...@@ -1001,7 +1003,9 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReqPtr req,
if (len < 0) if (len < 0)
return -2; return -2;
VIR_WARNINGS_NO_CAST_ALIGN
pup = (struct udphdr *) ((char *) pip + (pip->ihl << 2)); pup = (struct udphdr *) ((char *) pip + (pip->ihl << 2));
VIR_WARNINGS_RESET
len -= pip->ihl << 2; len -= pip->ihl << 2;
if (len < 0) if (len < 0)
return -2; return -2;
......
...@@ -324,7 +324,9 @@ procDHCPOpts(struct dhcp *dhcp, int dhcp_opts_len, ...@@ -324,7 +324,9 @@ procDHCPOpts(struct dhcp *dhcp, int dhcp_opts_len,
case DHCP_OPT_BCASTADDRESS: /* Broadcast address */ case DHCP_OPT_BCASTADDRESS: /* Broadcast address */
if (dhcp_opts_len >= 6) { if (dhcp_opts_len >= 6) {
VIR_WARNINGS_NO_CAST_ALIGN
uint32_t *tmp = (uint32_t *)&dhcpopt->value; uint32_t *tmp = (uint32_t *)&dhcpopt->value;
VIR_WARNINGS_RESET
(*bcastaddr) = ntohl(*tmp); (*bcastaddr) = ntohl(*tmp);
} }
break; break;
...@@ -498,8 +500,10 @@ learnIPAddressThread(void *arg) ...@@ -498,8 +500,10 @@ learnIPAddressThread(void *arg)
if (etherType == ETHERTYPE_IP && if (etherType == ETHERTYPE_IP &&
(header.len >= ethHdrSize + (header.len >= ethHdrSize +
sizeof(struct iphdr))) { sizeof(struct iphdr))) {
VIR_WARNINGS_NO_CAST_ALIGN
struct iphdr *iphdr = (struct iphdr*)(packet + struct iphdr *iphdr = (struct iphdr*)(packet +
ethHdrSize); ethHdrSize);
VIR_WARNINGS_RESET
vmaddr = iphdr->saddr; vmaddr = iphdr->saddr;
/* skip mcast addresses (224.0.0.0 - 239.255.255.255), /* skip mcast addresses (224.0.0.0 - 239.255.255.255),
* class E (240.0.0.0 - 255.255.255.255, includes eth. * class E (240.0.0.0 - 255.255.255.255, includes eth.
...@@ -514,8 +518,10 @@ learnIPAddressThread(void *arg) ...@@ -514,8 +518,10 @@ learnIPAddressThread(void *arg)
} else if (etherType == ETHERTYPE_ARP && } else if (etherType == ETHERTYPE_ARP &&
(header.len >= ethHdrSize + (header.len >= ethHdrSize +
sizeof(struct f_arphdr))) { sizeof(struct f_arphdr))) {
VIR_WARNINGS_NO_CAST_ALIGN
struct f_arphdr *arphdr = (struct f_arphdr*)(packet + struct f_arphdr *arphdr = (struct f_arphdr*)(packet +
ethHdrSize); ethHdrSize);
VIR_WARNINGS_RESET
switch (ntohs(arphdr->arphdr.ar_op)) { switch (ntohs(arphdr->arphdr.ar_op)) {
case ARPOP_REPLY: case ARPOP_REPLY:
vmaddr = arphdr->ar_sip; vmaddr = arphdr->ar_sip;
...@@ -535,14 +541,18 @@ learnIPAddressThread(void *arg) ...@@ -535,14 +541,18 @@ learnIPAddressThread(void *arg)
if (etherType == ETHERTYPE_IP && if (etherType == ETHERTYPE_IP &&
(header.len >= ethHdrSize + (header.len >= ethHdrSize +
sizeof(struct iphdr))) { sizeof(struct iphdr))) {
VIR_WARNINGS_NO_CAST_ALIGN
struct iphdr *iphdr = (struct iphdr*)(packet + struct iphdr *iphdr = (struct iphdr*)(packet +
ethHdrSize); ethHdrSize);
VIR_WARNINGS_RESET
if ((iphdr->protocol == IPPROTO_UDP) && if ((iphdr->protocol == IPPROTO_UDP) &&
(header.len >= ethHdrSize + (header.len >= ethHdrSize +
iphdr->ihl * 4 + iphdr->ihl * 4 +
sizeof(struct udphdr))) { sizeof(struct udphdr))) {
VIR_WARNINGS_NO_CAST_ALIGN
struct udphdr *udphdr= (struct udphdr *) struct udphdr *udphdr= (struct udphdr *)
((char *)iphdr + iphdr->ihl * 4); ((char *)iphdr + iphdr->ihl * 4);
VIR_WARNINGS_RESET
if (ntohs(udphdr->source) == 67 && if (ntohs(udphdr->source) == 67 &&
ntohs(udphdr->dest) == 68 && ntohs(udphdr->dest) == 68 &&
header.len >= ethHdrSize + header.len >= ethHdrSize +
......
...@@ -243,8 +243,10 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, ...@@ -243,8 +243,10 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool,
/* Given the way libdevmapper returns its data, I don't see /* Given the way libdevmapper returns its data, I don't see
* any way to avoid this series of casts. */ * any way to avoid this series of casts. */
VIR_WARNINGS_NO_CAST_ALIGN
next = names->next; next = names->next;
names = (struct dm_names *)(((char *)names) + next); names = (struct dm_names *)(((char *)names) + next);
VIR_WARNINGS_RESET
} while (next); } while (next);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册