From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32066 invoked by alias); 29 Jan 2020 20:13:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30648 invoked by uid 89); 29 Jan 2020 20:13:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jan 2020 20:13:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580328832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Qz1yF17ITHg0VcOIBBc6MwpoBga7Lbcmb4tloclfx8=; b=ENIZTe90kiB4A0WBbf5eF7EYDW5cMDL31PpjuqEagNJfXQF+5sD1d3vnTDnhSqgJ8/f9+y Mx9hzVOpNarPH6YYSR5hIzqGUdoZbyKwFVQVjt1UYaJ241573XNUW3Is9XUx2xDQYejYQf opF71U8a3oaNgcAu9qy3iQ8/cq2y3MI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-13-siUxEiw8NGKEhRgDsO-H0g-1; Wed, 29 Jan 2020 15:13:51 -0500 Received: by mail-wm1-f71.google.com with SMTP id p26so393226wmg.5 for ; Wed, 29 Jan 2020 12:13:50 -0800 (PST) Return-Path: Received: from ?IPv6:2001:8a0:f909:7b00:56ee:75ff:fe8d:232b? ([2001:8a0:f909:7b00:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id y20sm3308697wmj.23.2020.01.29.12.13.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2020 12:13:48 -0800 (PST) Subject: Re: [PATCH] Assert that 'length' > 0 on infcmd.c:construct_inferior_arguments To: Sergio Durigan Junior References: <20200129175943.1035-1-sergiodj@redhat.com> <640bcf24-b8c3-3c96-0ea5-2efdc29f039a@redhat.com> <87lfpqrqcg.fsf@redhat.com> Cc: GDB Patches From: Pedro Alves Message-ID: <9d7548f2-68e5-4b58-2fc2-9745b50e1dd4@redhat.com> Date: Wed, 29 Jan 2020 20:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <87lfpqrqcg.fsf@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2020-01/txt/msg00958.txt.bz2 On 1/29/20 7:54 PM, Sergio Durigan Junior wrote: > On Wednesday, January 29 2020, Pedro Alves wrote: >> Uppercase ARGC. But putting >> >> gdb_assert (argc > 0); >> >> at the top of the function instead as I originally suggested also works >> for me (tried current gcc master), which seems a bit better to me, as it >> covers both branches at once. Did it not work for you? This makes gcc see >> that the loops always run at least once. > > Yes, this should work. > > Updated patch below. The version you sent won't build for sure -- you're checking length instead of argc: @@ -268,6 +268,11 @@ construct_inferior_arguments (int argc, char **argv) { char *result; + /* argc should always be at least 1, but we double check this + here. This is also needed to silence -Werror-stringop + warnings. */ + gdb_assert (length > 0); This is OK with that fixed, but please update the commit log, here: "The solution here is to explicit check that 'length' is greater than 0. Since we're dealing with 'argc', I think it's pretty much guaranteed that it's going to be at least 1." I'd go with: The solution here is to assert that 'argc' is greater than 0 on entry, which makes GCC understand that the loops always run at least once, and thus 'length' is always > 0. ... and also update the commit's subject. I'd use Fix -Werror-stringop error on infcmd.c:construct_inferior_arguments instead, to talk in terms of what you're fixing instead of how you're fixing it. Thanks, Pedro Alves