From: Segher Boessenkool <segher@kernel.crashing.org>
To: Dumitru Ceara <dceara@redhat.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1
Date: Fri, 28 Jan 2022 11:37:09 -0600 [thread overview]
Message-ID: <20220128173709.GE614@gate.crashing.org> (raw)
In-Reply-To: <ae2014d7-1642-0ca2-b621-e080aa76e66d@redhat.com>
On Fri, Jan 28, 2022 at 05:16:58PM +0100, Dumitru Ceara wrote:
> On 1/28/22 16:27, Segher Boessenkool wrote:
> > On Fri, Jan 28, 2022 at 04:01:36PM +0100, Dumitru Ceara via Gcc-help wrote:
> >> void *l4data = p.l4_ofs != UINT16_MAX ? (char *) p.base_ + p.l4_ofs : NULL;
> >> struct hdr2 *h2 = l4data;
> >>
> >> memcpy(h2 + 1, &somedata[0], 6);
> >
> > l4data can be 0, and everything false apart from there on.
(Wow, writing homonyms already, I must be tired)./
> In general, yes, l4data can be 0, if p.l4_ofs == UINT16_MAX, which can
> only happen if pkt_bar() changed p.base_.
Try it with the user code fixed though? (Hint: the warning disappears).
> But the compiler can't know that for sure and the warning makes it sound
> like it's a sure thing:
>
> "warning: ‘memcpy’ writing 6 bytes into a region of size 0 overflows the
> destination"
Yes.
These warnings are often questionable, especially on otherwise broken
code like this, but they are far from helpful then :-(
What perhaps happens here is that the compiler realises l4data is not 0
(because otherwise the program would have undefined behaviour). But
your program explicitly makes that happen; perhaps the compiler should
have warned for that. (It will do a runtime error if ever that path is
taken, instead, as things are).
Segher
next prev parent reply other threads:[~2022-01-28 17:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 15:01 Dumitru Ceara
2022-01-28 15:27 ` Segher Boessenkool
2022-01-28 16:16 ` Dumitru Ceara
2022-01-28 17:37 ` Segher Boessenkool [this message]
2022-01-31 21:49 ` Martin Sebor
2022-01-31 22:01 ` Segher Boessenkool
2022-02-01 8:21 ` Jonathan Wakely
2022-02-01 5:18 ` Richard Sandiford
2022-02-01 14:42 ` Segher Boessenkool
2022-02-01 23:54 ` Martin Sebor
2022-02-02 10:12 ` Jonathan Wakely
2022-02-02 18:33 ` Segher Boessenkool
2022-02-02 20:44 ` Jonathan Wakely
2022-02-02 18:23 ` Segher Boessenkool
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=20220128173709.GE614@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=dceara@redhat.com \
--cc=gcc-help@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: link
Be 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).