From 681cfba45e9dcb2c462aef916f7dadda73c7253b Mon Sep 17 00:00:00 2001 From: whd <7058128+superwhd@users.noreply.github.com> Date: Fri, 23 Jul 2021 00:00:06 +0800 Subject: [PATCH] [posix] fix memcpy compiler warning false positive (#6840) In the issue, compiler complained we were copying 16 bytes to a location of 12 bytes. This was because in the check, the compiler thought we are going to copy data to a nlmsghdr which is 12 bytes. The reality is that we're copying data to a place behind nlmsghdr in req struct. --- src/posix/platform/netif.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 3eb58767c..fa0f2f2b0 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -578,7 +578,7 @@ static otError AddExternalRoute(const otIp6Prefix &aPrefix) otIp6AddressToString(&aPrefix.mPrefix, addrBuf, OT_IP6_ADDRESS_STRING_SIZE); inet_pton(AF_INET6, addrBuf, data); - AddRtAttr(&req.header, sizeof(req), RTA_DST, data, sizeof(data)); + AddRtAttr(reinterpret_cast(&req), sizeof(req), RTA_DST, data, sizeof(data)); AddRtAttrUint32(&req.header, sizeof(req), RTA_PRIORITY, kExternalRoutePriority); AddRtAttrUint32(&req.header, sizeof(req), RTA_OIF, netifIdx); @@ -627,7 +627,7 @@ static otError DeleteExternalRoute(const otIp6Prefix &aPrefix) otIp6AddressToString(&aPrefix.mPrefix, addrBuf, OT_IP6_ADDRESS_STRING_SIZE); inet_pton(AF_INET6, addrBuf, data); - AddRtAttr(&req.header, sizeof(req), RTA_DST, data, sizeof(data)); + AddRtAttr(reinterpret_cast(&req), sizeof(req), RTA_DST, data, sizeof(data)); AddRtAttrUint32(&req.header, sizeof(req), RTA_OIF, netifIdx); if (send(sNetlinkFd, &req, sizeof(req), 0) < 0)