Message ID | YuECqsVtvkrv0Btn@tucnak |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp275795pxt; Wed, 27 Jul 2022 02:18:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQRDClkqOJjQIAhMI74Dmkc9bDf7xGx/LdjAXhF56gVvnINk4j9ZnpXXkxi18GokH99h6n X-Received: by 2002:a17:907:7b9c:b0:72b:5652:a14a with SMTP id ne28-20020a1709077b9c00b0072b5652a14amr16820293ejc.86.1658913500782; Wed, 27 Jul 2022 02:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658913500; cv=none; d=google.com; s=arc-20160816; b=Ljlt5Z8qVxpNdoZHwbvBjPvmqCy5sLqu0jiRqF4bAx/xSMEUzg74wAmSpx6oAdZ7fX I5/p2leZql987T6DpXG4nbjJKHPndKQm9D9sLmIiEKnHHr99Mdr3J8Nd13DVpd2KhFn9 3hZPSxNX7fWoKTlofpak6hvMvohncHwRMzaqZqDFzmcphyB09ssrMcGOuSUD9cQsPFBP TYNbQtioJs5GBHMTAAW4Z0BYiAXYJ8l3LbHIaRNcX1UqQeOPJPA32ijjXxwd0wyK5XBx b8FgRs54qgPnNfSsKtNt2TlaGg4UBSCNWEaFraELQQdfJDXJiQPWrw3HwdMzAtu/mV1V /SGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/ftrF7qldxlrltMD8Uhgb+OtTiYLBrvySY9UemoZoAk=; b=fg72ZqcU4rCaB6o4t09QdX6oXJhjCe24c9WFZWK4hxmpQvQMUYttPS+jzXFhec/y9z k5xb8gy9WoUvhC/KDSPFkZXwDMOWgMFIiW7yYE4RuABVxzWmWavg6Sp6iMBhg4GEqraO 6RWXtJ1+y7QZiyrzwy5CH8FTpbz/yiSv+UOhVAE6sMwOG/R5Dq/ikVS5PUZpwajygcwE YjvAisxLO13n4ZnB0cMV5bHG44AbszCwEs8C66WiQxhBSbeFvuCUusThFplwnG3aYxYN uWOfWigjdagK2Kd6cPdpo+uOuJSjftB/A9Mny5vb9JhqYB4XGxU0V3Up2uPJC1u7NjBG ifMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tDzCNl64; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i20-20020a05640242d400b00436c8577a9bsi22540045edc.464.2022.07.27.02.18.20 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 02:18:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tDzCNl64; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C47D385702D for <ouuuleilei@gmail.com>; Wed, 27 Jul 2022 09:18:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C47D385702D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658913499; bh=/ftrF7qldxlrltMD8Uhgb+OtTiYLBrvySY9UemoZoAk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tDzCNl64PKU13WUnTjB4CYjp23PWWWEuCTbAD2Ldy61sAKffvSx3gGszU6L9odZF/ hLThZZ9SpYQzzt34AVxGRdBz12qr3foBFvCsgoNm9NDmvE/AssGyuIv84OnfF7k1vC Wu5cVWaxf4kg0UXSJHk9QuZDrRz80H8TX0lqLHhE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4A6B23857374 for <gcc-patches@gcc.gnu.org>; Wed, 27 Jul 2022 09:17:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A6B23857374 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-529-5a8sdW5iOT68T01OJoR8fw-1; Wed, 27 Jul 2022 05:17:34 -0400 X-MC-Unique: 5a8sdW5iOT68T01OJoR8fw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 619652813D30; Wed, 27 Jul 2022 09:17:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E00590A04; Wed, 27 Jul 2022 09:17:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 26R9HVPc2208137 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 11:17:31 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 26R9HUaC2208136; Wed, 27 Jul 2022 11:17:30 +0200 Date: Wed, 27 Jul 2022 11:17:30 +0200 To: Richard Biener <rguenther@suse.de> Subject: [PATCH] opts: Add an assertion to help static analyzers [PR106332] Message-ID: <YuECqsVtvkrv0Btn@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jakub Jelinek <jakub@redhat.com> Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1739496883187858284?= X-GMAIL-MSGID: =?utf-8?q?1739496883187858284?= |
Series |
opts: Add an assertion to help static analyzers [PR106332]
|
|
Commit Message
Jakub Jelinek
July 27, 2022, 9:17 a.m. UTC
Hi! This function would have UB if called with empty candidates vector (accessing p[-1] where p is malloc (0) result). As analyzed in the PR, we never call it with empty vector, so this just adds an assertion to make it clear. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-07-27 Jakub Jelinek <jakub@redhat.com> PR middle-end/106332 * opts-common.cc (candidates_list_and_hint): Add gcc_checking_assert that candidates is not an empty vector. Jakub
Comments
On Wed, 27 Jul 2022, Jakub Jelinek wrote: > Hi! > > This function would have UB if called with empty candidates vector > (accessing p[-1] where p is malloc (0) result). > As analyzed in the PR, we never call it with empty vector, so this just > adds an assertion to make it clear. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK, I think we can make this a gcc_assert even. Richard. > 2022-07-27 Jakub Jelinek <jakub@redhat.com> > > PR middle-end/106332 > * opts-common.cc (candidates_list_and_hint): Add gcc_checking_assert > that candidates is not an empty vector. > > --- gcc/opts-common.cc.jj 2022-02-04 14:36:55.439599237 +0100 > +++ gcc/opts-common.cc 2022-07-26 11:21:49.785919993 +0200 > @@ -1347,6 +1347,8 @@ candidates_list_and_hint (const char *ar > const char *candidate; > char *p; > > + gcc_checking_assert (!candidates.is_empty ()); > + > FOR_EACH_VEC_ELT (candidates, i, candidate) > len += strlen (candidate) + 1; > > > Jakub > >
--- gcc/opts-common.cc.jj 2022-02-04 14:36:55.439599237 +0100 +++ gcc/opts-common.cc 2022-07-26 11:21:49.785919993 +0200 @@ -1347,6 +1347,8 @@ candidates_list_and_hint (const char *ar const char *candidate; char *p; + gcc_checking_assert (!candidates.is_empty ()); + FOR_EACH_VEC_ELT (candidates, i, candidate) len += strlen (candidate) + 1;