From patchwork Thu Mar 22 21:38:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martijn Dekker X-Patchwork-Id: 10302359 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D881600CC for ; Thu, 22 Mar 2018 21:39:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2779B2898B for ; Thu, 22 Mar 2018 21:39:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BA2A28A05; Thu, 22 Mar 2018 21:39:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 299FC2898B for ; Thu, 22 Mar 2018 21:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751657AbeCVVjH (ORCPT ); Thu, 22 Mar 2018 17:39:07 -0400 Received: from kahlil.inlv.org ([37.59.109.123]:51704 "EHLO kahlil.inlv.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbeCVVjH (ORCPT ); Thu, 22 Mar 2018 17:39:07 -0400 Received: from breedzicht.local (inlv.demon.nl [212.238.240.159]) (authenticated bits=0) by kahlil.inlv.org (8.14.9/8.14.4) with ESMTP id w2MLcxxo001216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 22 Mar 2018 22:38:59 +0100 Subject: Re: [PATCH] don't record empty IFS scan regions To: Harald van Dijk , DASH shell mailing list References: <5bf00c16-361b-0128-b1ef-c0668dc557f2@gigawatt.nl> From: Martijn Dekker Message-ID: <72d906db-0734-cef7-e941-2c306835974a@inlv.org> Date: Thu, 22 Mar 2018 22:38:59 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <5bf00c16-361b-0128-b1ef-c0668dc557f2@gigawatt.nl> Content-Language: en-GB Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Op 22-03-18 om 20:28 schreef Harald van Dijk: > On 22/03/2018 03:40, Martijn Dekker wrote: >> evalvar() records empty expansion results (varlen == 0) as string >> regions that need to be scanned for IFS characters. This is pointless, >> because there is nothing to split. > > varlen may be set to -1 when an unset variable is expanded. If it's > beneficial to avoid recording empty regions to scan for IFS characters, > should those also be excluded? Agreed. Updated patch attached. >> This patch fixes the bug that, given no positional parameters, unquoted >> $@ and $* incorrectly generate one empty field (they should generate no >> fields). Apparently that was a side effect of the above. > > This seems weird though. If you want to remove the recording of empty > regions because they are pointless, then how does removing them fix a > bug? Doesn't this show that empty regions do have an effect? Perhaps > they're not supposed to have any effect, perhaps it's a specific > combination of empty regions and something else that triggers some bug, > and perhaps that combination can no longer occur with your patch. The latter is my guess, but I haven't had time to investigate it. I *did* investigate whether the patch introduces other bugs, and haven't found any new ones. I successfully ran this large IFS and PPs test script from AT&T against dash with this patch: http://web.archive.org/web/20050414022354/http://www.research.att.com/~gsf/public/ifs.sh My own modernish regression test suite, which tests some pretty crazy things including lots of IFS and positional parameters stuff, also passes completely: git clone https://github.com/modernish/modernish cd modernish dash bin/modernish --test (still under development, may occasionally break) - M. diff --git a/src/expand.c b/src/expand.c index 705fef7..c3d20a4 100644 --- a/src/expand.c +++ b/src/expand.c @@ -771,7 +771,7 @@ vsplus: if (subtype == VSNORMAL) { record: - if (!easy) + if (!easy || varlen <= 0) goto end; recordregion(startloc, expdest - (char *)stackblock(), quoted); goto end;