This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
- From: "luto at mit dot edu" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 20 Nov 2013 21:31:22 +0000
- Subject: [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=16197
Bug ID: 16197
Summary: CMSG_DATA results in (possibly correct) string
aliasing warnings on gcc
Product: glibc
Version: 2.17
Status: NEW
Severity: normal
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: luto at mit dot edu
CC: drepper.fsp at gmail dot com
Using CMSG_DATA on most gcc configurations gives a string aliasing warning.
This happens because struct cmsg_hdr is:
struct cmsghdr
{
size_t cmsg_len;
int cmsg_level;
int cmsg_type;
__extension__ unsigned char __cmsg_data [];
};
GCC thinks that __cmsg_data is an array of objects of type unsigned char, in
which case it's illegal to access them through a pointer to anything else (as
CMSG_DATA does). I'm not sure whether it's legal to put objects of, for
example, type int into storage defined by an array of type unsigned char, but
I'm not particularly surprised that gcc warns.
Anything like this:
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&hdr);
if (cmsg) {
/* This is IPPROTO_IP / IP_TTL */
if (cmsg->cmsg_level == 0 && cmsg->cmsg_type == 2) {
use(*(int *)CMSG_DATA(cmsg));
}
}
will trigger the warning if built with -Wall -O2.
There's a trivial fix: stop using flexible arrays. The pre-C99
non-gcc-extension-using variant (which is already in bits/socket.h) is fine.
--
You are receiving this mail because:
You are on the CC list for the bug.