[PATCH] D23657: Remove some false positives when taking the address of packed members

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 3 16:12:55 PDT 2016


joerg added a comment.

The following is from my comment on the original commit.

I'm trying this patch now. Two instances here show false positives. Some
others are misuse/overuse of __packed, it is time consuming to check all
of them.

- sbin/route

https://nxr.netbsd.org/xref/src/sbin/route/route.c#1009 triggers the warning:

  union mpls_shim *ms = &su->smpls.smpls_addr;

where su is defined as:

  union sockunion {
      ...
      struct  sockaddr_mpls smpls;
  };

and sockaddr_mpls in turn is https://nxr.netbsd.org/xref/src/sys/netmpls/mpls.h#66

  struct sockaddr_mpls {
      uint8_t smpls_len;
      uint8_t smpls_family;
      uint8_t smpls_pad[2];
      union mpls_shim smpls_addr;
  } __packed;

smpls_addr is a union of a uint32_t and matching bit field. The alignment of sockunion and the explicit padding ensures that all fields can be accessed correctly.

- sbin/ifconfig

Member access is https://nxr.netbsd.org/xref/src/sbin/ifconfig/ieee80211.c#969
The macro is defined at https://nxr.netbsd.org/xref/src/sbin/ifconfig/ieee80211.c#928

Most importantly, this effective casts immediately to (unsigned) char and therefore doesn't care about any misalignment.


https://reviews.llvm.org/D23657





More information about the cfe-commits mailing list