From patchwork Thu Mar 22 10:20:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martijn Dekker X-Patchwork-Id: 10301151 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 93CFA60385 for ; Thu, 22 Mar 2018 10:20:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C0B29AFC for ; Thu, 22 Mar 2018 10:20:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73F6229B01; Thu, 22 Mar 2018 10:20:54 +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 1044329AFC for ; Thu, 22 Mar 2018 10:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753338AbeCVKUx (ORCPT ); Thu, 22 Mar 2018 06:20:53 -0400 Received: from kahlil.inlv.org ([37.59.109.123]:59462 "EHLO kahlil.inlv.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752870AbeCVKUx (ORCPT ); Thu, 22 Mar 2018 06:20:53 -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 w2MAKpAh007194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Thu, 22 Mar 2018 11:20:52 +0100 From: Martijn Dekker Subject: [PATCH] [v2] don't record empty IFS scan regions To: DASH shell mailing list Message-ID: Date: Thu, 22 Mar 2018 11:20:51 +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 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 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. This patch fixes the following bug, which is apparently a side effect of the above: $ dash -c 'IFS=; set -- set -- $@ $*; printf $#, set -- $@ $*; printf $#, set -- $@ $*; echo $#' 2,4,8 Expected output: 0,0,0. Given set & empty IFS and no positional parameters, unquoted $@ and $* incorrectly generate one empty field (they should generate no fields). - M. diff --git a/src/expand.c b/src/expand.c index 705fef7..03a9b0c 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;