public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dumitru Ceara <dceara@redhat.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1
Date: Fri, 28 Jan 2022 17:16:58 +0100	[thread overview]
Message-ID: <ae2014d7-1642-0ca2-b621-e080aa76e66d@redhat.com> (raw)
In-Reply-To: <20220128152748.GD614@gate.crashing.org>

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.
> 

In general, yes, l4data can be 0, if p.l4_ofs == UINT16_MAX, which can
only happen if pkt_bar() changed p.base_.

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"

In particular [0], we know for sure that l4data will not be NULL and we
can avoid the warning with an extra assertion.  It's just a bit
inconvenient I guess.

In any case, thanks for the quick response!

Regards,
Dumitru

[0]
https://github.com/dceara/ovn/commit/4796a6c480d5d2e35ec2e20ed0ae23ab787fa175


  reply	other threads:[~2022-01-28 16:17 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 [this message]
2022-01-28 17:37     ` Segher Boessenkool
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=ae2014d7-1642-0ca2-b621-e080aa76e66d@redhat.com \
    --to=dceara@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=segher@kernel.crashing.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).