public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "luto at mit dot edu" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc Date: Wed, 20 Nov 2013 21:31:00 -0000 [thread overview] Message-ID: <bug-16197-131@http.sourceware.org/bugzilla/> (raw) 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.
next reply other threads:[~2013-11-20 21:31 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-11-20 21:31 luto at mit dot edu [this message] 2013-11-21 0:26 ` [Bug libc/16197] " bugdal at aerifal dot cx 2013-11-21 5:32 ` luto at mit dot edu 2013-12-02 6:45 ` crrodriguez at opensuse dot org 2014-06-13 11:59 ` fweimer at redhat dot com 2015-08-27 22:18 ` [Bug network/16197] " jsm28 at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-16197-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).