summaryrefslogtreecommitdiff
path: root/socketutils.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2016-05-19 01:23:40 +0000
committerDmitry V. Levin <ldv@altlinux.org>2016-05-21 09:33:12 +0000
commit7b6979701b5ddda47ba53f82381a5f412708b0ad (patch)
tree5d9f55f8d988ac7c8f5b10ca9b9f9852ac5f56fa /socketutils.c
parent28e955d747661fd0f437e70f41e477c9161467df (diff)
downloadstrace-7b6979701b5ddda47ba53f82381a5f412708b0ad.tar.gz
Fix one more code pattern that might break gcc strict aliasing rules
* socketutils.c (receive_responses): Turn static buffer into a union to avoid breaking of gcc strict aliasing rules. * tests/netlink_inet_diag.c (check_responses): Likewise. * tests/netlink_netlink_diag.c (check_responses): Likewise. * tests/netlink_unix_diag.c (check_responses): Likewise.
Diffstat (limited to 'socketutils.c')
-rw-r--r--socketutils.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/socketutils.c b/socketutils.c
index a0d9310d9..5d8d3ed98 100644
--- a/socketutils.c
+++ b/socketutils.c
@@ -187,13 +187,17 @@ receive_responses(const int fd, const unsigned long inode,
int (* parser) (const char *, const void *,
int, unsigned long))
{
- static long buf[8192 / sizeof(long)];
+ static union {
+ struct nlmsghdr hdr;
+ long buf[8192 / sizeof(long)];
+ } hdr_buf;
+
struct sockaddr_nl nladdr = {
.nl_family = AF_NETLINK
};
struct iovec iov = {
- .iov_base = buf,
- .iov_len = sizeof(buf)
+ .iov_base = hdr_buf.buf,
+ .iov_len = sizeof(hdr_buf.buf)
};
int flags = 0;
@@ -212,7 +216,7 @@ receive_responses(const int fd, const unsigned long inode,
return false;
}
- const struct nlmsghdr *h = (struct nlmsghdr *) buf;
+ const struct nlmsghdr *h = &hdr_buf.hdr;
if (!NLMSG_OK(h, ret))
return false;
for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {