public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "neoxic at icloud dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106939] New: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning Date: Wed, 14 Sep 2022 05:12:10 +0000 [thread overview] Message-ID: <bug-106939-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106939 Bug ID: 106939 Summary: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: neoxic at icloud dot com Target Milestone: --- Working with embedded applications, one often deals with manipulating memory regions via symbols defined in a linker script. Please consider the following snippet: ----------------------------------------------------- #include <string.h> extern char _src, _dst; // Defined by the linker int main(void) { memcpy(&_dst, &_src + 1024, 1111); return 0; } ----------------------------------------------------- Compilation with GCC 12.2.0 yields lots of warnings: ----------------------------------------------------- $ cc -O2 -Wall -Wextra -fno-strict-aliasing -fwrapv a.c a.c: In function ‘main’: a.c:6:29: warning: array subscript 1024 is outside array bounds of ‘char[1]’ [-Warray-bounds] 6 | memcpy(&_dst, &_src + 1024, 1111); | ~~~~~~^~~~~~ a.c:3:13: note: at offset 1024 into object ‘_src’ of size 1 3 | extern char _src, _dst; // Defined by the linker | ^~~~ a.c:6:9: warning: ‘memcpy’ forming offset [1, 1110] is out of the bounds [0, 1] of object ‘_dst’ with type ‘char’ [-Warray-bounds] 6 | memcpy(&_dst, &_src + 1024, 1111); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.c:3:19: note: ‘_dst’ declared here 3 | extern char _src, _dst; // Defined by the linker | ^~~~ ----------------------------------------------------- These symbols are used as mere address anchors, they don't contain anything. But no matter what I do like changing their type, casting their addresses, etc, I can't get rid of the pesky sticky warnings now. Is there a clean way to work around these warning without turning off Warray-bounds?
next reply other threads:[~2022-09-14 5:12 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-14 5:12 neoxic at icloud dot com [this message] 2022-09-14 5:18 ` [Bug c/106939] " pinskia at gcc dot gnu.org 2022-09-14 5:22 ` neoxic at icloud dot com 2022-09-14 5:38 ` pinskia at gcc dot gnu.org 2022-09-14 5:50 ` neoxic at icloud dot com 2022-09-14 16:09 ` pinskia at gcc dot gnu.org 2022-09-14 18:41 ` neoxic at icloud dot com 2022-09-22 19:26 ` jakub at gcc dot gnu.org 2022-09-24 1:21 ` neoxic at icloud dot com
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-106939-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).