public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/109298] New: warning: array subscript ‘...’ is partly outside array bounds of ‘...’ Date: Mon, 27 Mar 2023 12:59:37 +0000 [thread overview] Message-ID: <bug-109298-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109298 Bug ID: 109298 Summary: warning: array subscript ‘...’ is partly outside array bounds of ‘...’ Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ubizjak at gmail dot com Target Milestone: --- This warning/error is actually emitted when compiling drivers/infiniband/core/user_mad.c linux source file. The testcase: --cut here-- enum { IB_MGMT_RMPP_HDR = 36, IB_MGMT_RMPP_DATA = 220, }; struct ib_umad_packet { int hdr; unsigned char data[]; }; struct ib_rmpp_mad { int class; unsigned char data[IB_MGMT_RMPP_DATA]; }; int foo (const unsigned char *buf) { struct ib_umad_packet *packet; struct ib_rmpp_mad *rmpp_mad; packet = __builtin_malloc (sizeof *packet + IB_MGMT_RMPP_HDR); __builtin_memcpy (&packet->data, buf, IB_MGMT_RMPP_HDR); rmpp_mad = (struct ib_rmpp_mad *) packet->data; return rmpp_mad->class; } --cut here-- -O2 -Wall test.c: In function ‘foo’: test.c:27:18: warning: array subscript ‘struct ib_rmpp_mad[0]’ is partly outside array bounds of ‘unsigned char[40]’ [-Warray-bounds=] 27 | return rmpp_mad->class; | ^~ test.c:21:12: note: at offset 4 into object of size 40 allocated by ‘__builtin_malloc’ 21 | packet = __builtin_malloc (sizeof *packet + IB_MGMT_RMPP_HDR); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Adding -fno-strict-aliasing to compile flags does not help.
next reply other threads:[~2023-03-27 12:59 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-27 12:59 ubizjak at gmail dot com [this message] 2023-03-28 7:07 ` [Bug tree-optimization/109298] " rguenth 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-109298-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.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).