From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by sourceware.org (Postfix) with ESMTPS id E5BD1386EC13 for ; Thu, 17 Mar 2022 17:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5BD1386EC13 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nefkom.net Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4KKD266HGDz1qxly; Thu, 17 Mar 2022 18:01:34 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4KKD264LMwz1qqkB; Thu, 17 Mar 2022 18:01:34 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id tOevZ7H5p5DE; Thu, 17 Mar 2022 18:01:33 +0100 (CET) X-Auth-Info: /Sot5CHpBnfs+yVC6EOvXqKOptd2goZaplmjrh1Tkj+OiKZbtIiLBtpAxX+AU2Dl Received: from igel.home (ppp-46-244-165-77.dynamic.mnet-online.de [46.244.165.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 17 Mar 2022 18:01:33 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id 1B0732C3A8B; Thu, 17 Mar 2022 18:01:33 +0100 (CET) From: Andreas Schwab To: Jeff Law via Gcc-patches Cc: Marek Polacek , Jeff Law , Jakub Jelinek , Martin Sebor Subject: Re: [PATCH v2] middle-end/104854: Limit strncmp overread warnings References: <20220311071236.2349381-1-siddhesh@gotplt.org> <20220315053158.1486555-1-siddhesh@gotplt.org> <01c49ecb-cd91-3bcc-c5a0-97e81281e1dd@gotplt.org> <4104ab01-c36c-12e9-5601-6d99019f6bef@redhat.com> X-Yow: Let's all show human CONCERN for REVEREND MOON's legal difficulties!! Date: Thu, 17 Mar 2022 18:01:33 +0100 In-Reply-To: (Jeff Law via Gcc-patches's message of "Thu, 17 Mar 2022 10:46:33 -0600") Message-ID: <87r170fr82.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 17:01:41 -0000 On Mär 17 2022, Jeff Law via Gcc-patches wrote: > On Thu, Mar 17, 2022 at 9:32 AM Marek Polacek via Gcc-patches < > gcc-patches@gcc.gnu.org> wrote: >> I think I agree, I've tried >> >> #include >> char a[] = "abc"; >> char b[] = "abcd"; >> >> int f (void) >> { >> return strncmp (a, b, 8); >> } >> >> where I get >> >> t.c:7:10: warning: ‘strncmp’ specified bound 8 exceeds source size 5 >> [-Wstringop-overread] >> 7 | return strncmp (a, b, 8); // -Wstringop-overread >> | ^~~~~~~~~~~~~~~~~ >> >> even without -Wall. strncmp sees that a[3] is '\0' so it stops comparing >> and there's no UB. >> > This one is a clear case where warning is bad. Both arguments are > constant and we can determine they are NUL terminated and an overread will > never occur. No deep analysis really needed here. Both a and b are modifiable, thus the compiler cannot assume anything. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."