From patchwork Wed Jul 27 09:17:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 56358 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96C643857022 for ; Wed, 27 Jul 2022 09:18:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96C643857022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658913485; 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=dmoDxa6BiMcSBOViamgAzfEZOuVJp53Wcux39hU/sIB9GSK6SjZckJdYGIfWWPwZd YcliRN4EGpbHA9NFrj6gVv0UR+j6Kgre0Ml0CJT6CBdBbzLKbkq5HhIIYfV9fUZtLX vJw03fs8hUym2pfhoCbJ0co/7+evwfvQX7kFe5VQ= 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 ; 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 Subject: [PATCH] opts: Add an assertion to help static analyzers [PR106332] Message-ID: 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-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 PR middle-end/106332 * opts-common.cc (candidates_list_and_hint): Add gcc_checking_assert that candidates is not an empty vector. 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;