From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D324B385840C for ; Fri, 28 Jan 2022 16:17:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D324B385840C Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-hAdabZyTOVyaMYol6rllEQ-1; Fri, 28 Jan 2022 11:17:01 -0500 X-MC-Unique: hAdabZyTOVyaMYol6rllEQ-1 Received: by mail-wr1-f71.google.com with SMTP id o26-20020adfa11a000000b001dd1d3a73c7so2389722wro.21 for ; Fri, 28 Jan 2022 08:17:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=2oq/HLmzrWGBftw5/zxNZHn9Mu6vD2JFERfF04wX1SE=; b=P/C3CdVc6MPASoBZdNjdRUR8KCIySAcMS9d0nm4iWrYQhRhc53+IsNBOdDmSglMBcV P15rtu6/9BHXynf6QPqq1CqCUQ5IxtOysaTTCI1XFpE6kk9IqBacUiL4xwViIfwA02J0 Zd31IBRrEUeEykrHYNfQgvmgrFbXDmqO+i1tsTRVH8VwgcW0+VAB2IN2m0oRXbnZSkbw 9ReTy/EGuy+YNeVdmsWhy+HDlpFGDJ9wp3YV9183rOHDp9G+0fOur4GDQZILYA6Xa1Wc /SAQ0HpyuyGq3evpxo4dldMG6061vqE6+ZzNGlVnCV9dkQRfy4MO5yPqHQecD2FFmWe1 V0Dg== X-Gm-Message-State: AOAM531w8CBA6YQy+zTVWhQ9lZq2wrbvgSwWSHqfBsDehcXMYNhzgY5C TEzo4U1TM7MFGLsbK8t4IKn6YEXiLcN9wJM9Vn10ccy5fGquxvor/9alnZ0s0QA7gJ0c6bpe6pK 0mMcZiUI865llow== X-Received: by 2002:a1c:730e:: with SMTP id d14mr16643728wmb.64.1643386619753; Fri, 28 Jan 2022 08:16:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHccnhJogUmHumzY4NSTNikjObDpmXND3ysyJJjH/FCTLs6JqPjTst+hrfkT0moPzMQAeE1A== X-Received: by 2002:a1c:730e:: with SMTP id d14mr16643709wmb.64.1643386619371; Fri, 28 Jan 2022 08:16:59 -0800 (PST) Received: from [192.168.101.16] (i87195.upc-i.chello.nl. [62.195.87.195]) by smtp.gmail.com with ESMTPSA id a18sm5098683wrw.5.2022.01.28.08.16.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 08:16:58 -0800 (PST) Message-ID: Date: Fri, 28 Jan 2022 17:16:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1 To: Segher Boessenkool Cc: gcc-help@gcc.gnu.org References: <8d42151f-7be2-4d67-5b46-a83ba55d5c1c@redhat.com> <20220128152748.GD614@gate.crashing.org> From: Dumitru Ceara In-Reply-To: <20220128152748.GD614@gate.crashing.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2022 16:17:06 -0000 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