This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/47418] warning: array subscript is above array bounds at O2 with sin6_addr
- From: "chantry.xavier at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 23 Jan 2011 02:02:37 +0000
- Subject: [Bug c/47418] warning: array subscript is above array bounds at O2 with sin6_addr
- Auto-submitted: auto-generated
- References: <bug-47418-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47418
Xavier <chantry.xavier at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |chantry.xavier at gmail dot
| |com
--- Comment #2 from Xavier <chantry.xavier at gmail dot com> 2011-01-23 02:02:18 UTC ---
(In reply to comment #1)
> Also of note is the commented bit in the test case- if you instead dereference
> the s6_addr bit of the union, it all works without warnings.
>
> In the preprocessed source, replace
> ap = (char *)&u.sin6.sin6_addr;
>
> with:
> ap = (char *)&u.sin6.sin6_addr.__in6_u.__u6_addr8;
Actually it works with any member from __in6.u union.
It seems gcc gets confused with the other anonymous union, and use the size of
struct sockaddr instead of struct sockaddr_in6.
I've got a simpler testcase which shows another interesting information : gcc
gets confused when the sign of ap is the same as the size of the smallest
struct/array of the union, and different from the sign of the big member that
should be used.