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 3ECBD385DDCF for ; Tue, 11 Jun 2024 10:39:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3ECBD385DDCF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3ECBD385DDCF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718102379; cv=none; b=vfrtIt/zdA8zvAVBBlUjqBVBZ0mlrIYkvCLDmzT2f+Fh55GzZgtpH2FYcMPJA0C4OuQtlWOrTGMYlmnv29TVQMLTKK2wOvQgpQzBhgzTeSwtYxee3T6Sh2Fsr2ZNAsQdkNLgjYVhc8DsLSQxYsgDzqaF6nYrQwIRNqqcDt6zWts= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718102379; c=relaxed/simple; bh=BannLwGmSjDK7bLIcnZir3MJmWO3CjPoZLmffBJDc3w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lZ+Nk7eB5xjZw4ZFoR/AFKTx/S5p+PwQQd/imYlg+7jPiFtWiDkxJL5hLiDedqTVUh9Hc5suZALWTmuGnNbviRXZIwEjHx0TvB10vJx/bvLOKuNNm3hfURP5LT+yKGqALdPi16MOZ16O5JsKNYSiH16NHAsav8KRj9PteccM8Pk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718102376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IWNCHfHfSM+ptK/54/VFywzJPiJJ5krWO2ndblQfmlo=; b=MN+F8eJttUxP3qUcE59p4dN9R57Rwbw0NM2l4jXf1ZwDL6dw9OdZ15f5I6M/t2MpsW5g6F 4O04jeQ/svaR5Q65ExawCuxoOj91+Aoq0p3Z7Ce2u5GqPAaqZaKdUSA3+u/mDilyjWr5kR w+vl8CIJfR9qpXKN1RJ8NXswNHdTnVo= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-ZBs6xilGPTijh8_hAMm_Fg-1; Tue, 11 Jun 2024 06:39:35 -0400 X-MC-Unique: ZBs6xilGPTijh8_hAMm_Fg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-35f2730d114so1187878f8f.1 for ; Tue, 11 Jun 2024 03:39:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718102373; x=1718707173; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IWNCHfHfSM+ptK/54/VFywzJPiJJ5krWO2ndblQfmlo=; b=UvetF9211MS8vJgVr8EzZQ/k8b+tC8prMVIGF8sfbIdbMBnMgxSHAIUdcCkljYmwo4 3e7CSB2s2nzI4V1tbnbD79GyZ0Gg3WQ1EWzULm4BRoOf2AiG7ZVcasiWZAi2TTxgMIc7 vsiNzKfLLtewHEdwMgRKvwyxmAVHz9kjq80ENRZvOn+ZJM2Nw58/cXgkq5JTBT2HDzhP Mm2uQ+cRXmVw8AQMD8OntaVjSCOHiJlPwo3styaW++gX/CG9IY1Kjl+7FOCRGDFfewxg +p5yLcPYXDd0S/08oEshr2t4fogAig4qIs9SnNCT4wRKX++Ko9Kis0WYjgH5Q+L6UWpG 2ekw== X-Forwarded-Encrypted: i=1; AJvYcCVvxiqWO8wwNnHWQy2nNNn+wrxz/n94YrckbD1yUgv9l1+8DrjfusvDq4SrrfZDag/f8BwagP9GuFQwMBM7K6nNOBFcc1CPhw== X-Gm-Message-State: AOJu0YwmE3p2E7Ys8+w5SSLpBfwAvsX/d8tr+JoxQNnRCri1oSJcK3CA 3mVaBLYTxLS+oPaK9rHi+PfZVa6TCeE54GnFKDk+kfd1YjCvsq7EWeZV2AJtJ627otRoHd8MjV2 zmI8GB2z+twKGnxpo+nd8IGltDzDknimiucbXV9FAhbdsrtS0THpe5q/gqDUo/Bk= X-Received: by 2002:adf:f38b:0:b0:354:e4da:ba52 with SMTP id ffacd0b85a97d-35f2b27ede7mr1911752f8f.10.1718102373364; Tue, 11 Jun 2024 03:39:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8CYAbTFLuY4RK+wAIc5uxkBzqLXkP0peVKq7x4ffCDeeoZv1ZSOWWFE72OVP9YHrNramzZg== X-Received: by 2002:adf:f38b:0:b0:354:e4da:ba52 with SMTP id ffacd0b85a97d-35f2b27ede7mr1911732f8f.10.1718102372781; Tue, 11 Jun 2024 03:39:32 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5d69e71sm13317887f8f.65.2024.06.11.03.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 03:39:32 -0700 (PDT) From: Andrew Burgess To: Jeff Law , gcc-patches@gcc.gnu.org Subject: Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space In-Reply-To: <79be7bb1-9003-4f0b-8dbf-5c717b9ce82f@gmail.com> References: <24a8d878590403540bc9b579ba58805985a4d2f7.1701881419.git.aburgess@redhat.com> <37b3a30868139bab59155717f6bff1ed08dbca76.1707585836.git.aburgess@redhat.com> <79be7bb1-9003-4f0b-8dbf-5c717b9ce82f@gmail.com> Date: Tue, 11 Jun 2024 11:39:31 +0100 Message-ID: <87wmmvahlo.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Jeff Law writes: > On 2/10/24 10:26 AM, Andrew Burgess wrote: >> GDB makes use of the libiberty function buildargv for splitting the >> inferior (program being debugged) argument string in the case where >> the inferior is not being started under a shell. >> >> I have recently been working to improve this area of GDB, and noticed >> some unexpected behaviour to the libiberty function buildargv, when >> the input is a string consisting only of white space. >> >> What I observe is that if the input to buildargv is a string >> containing only white space, then buildargv will return an argv list >> containing a single empty argument, e.g.: >> >> char **argv = buildargv (" "); >> assert (*argv[0] == '\0'); >> assert (argv[1] == NULL); >> >> We get the same output from buildargv if the input is a single space, >> or multiple spaces. Other white space characters give the same >> results. >> >> This doesn't seem right to me, and in fact, there appears to be a work >> around for this issue in expandargv where we have this code: >> >> /* If the file is empty or contains only whitespace, buildargv would >> return a single empty argument. In this context we want no arguments, >> instead. */ >> if (only_whitespace (buffer)) >> { >> file_argv = (char **) xmalloc (sizeof (char *)); >> file_argv[0] = NULL; >> } >> else >> /* Parse the string. */ >> file_argv = buildargv (buffer); >> >> I think that the correct behaviour in this situation is to return an >> empty argv array, e.g.: >> >> char **argv = buildargv (" "); >> assert (argv[0] == NULL); >> >> And it turns out that this is a trivial change to buildargv. The diff >> does look big, but this is because I've re-indented a block. Check >> with 'git diff -b' to see the minimal changes. I've also removed the >> work around from expandargv. >> >> When testing this sort of thing I normally write the tests first, and >> then fix the code. In this case test-expandargv.c has sort-of been >> used as a mechanism for testing the buildargv function (expandargv >> does call buildargv most of the time), however, for this particular >> issue the work around in expandargv (mentioned above) masked the >> buildargv bug. >> >> I did consider adding a new test-buildargv.c file, however, this would >> have basically been a copy & paste of test-expandargv.c (with some >> minor changes to call buildargv). This would be fine now, but feels >> like we would eventually end up with one file not being updated as >> much as the other, and so test coverage would suffer. >> >> Instead, I have added some explicit buildargv testing to the >> test-expandargv.c file, this reuses the test input that is already >> defined for expandargv. >> >> Of course, once I removed the work around from expandargv then we now >> do always call buildargv from expandargv, and so the bug I'm fixing >> would impact both expandargv and buildargv, so maybe the new testing >> is redundant? I tend to think more testing is always better, so I've >> left it in for now. > So just an FYI. Sometimes folks include the -b diffs as well for these > scenarios. THe problem with doing so (as I recently stumbled over > myself) is the bots which monitor the list and apply patches get quite > confused by that practice. Anyway, just something to be aware of. > > As for testing, I tend to agree, more is better unless we're highly > confident its redundant. So I'll go with your judgment on > redundant-ness of the test. > > As with the prior patch, you'll need to run it through the usual > bootstrap/regression cycle and cobble together a ChangeLog. > > OK once those things are taken care of. Jeff, Thanks for looking these patches over. For testing, using current(ish) gcc HEAD, on x86-64 GNU/Linux, I: ../src/configure --prefix=$(cd .. && pwd)/install make make check I did this with / without my patch and then: find . -name "*.sum" ... compare all .sum files ... There was no change in any of the .sum files. 1. Am I correct that this will have run the bootstrap test by default? 2. Is there any other testing I should be doing? 3. If not, am I OK to apply both patches in this series? Thanks, Andrew