From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7445 invoked from network); 22 Jun 2020 10:28:38 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 22 Jun 2020 10:28:38 -0000 Received: (qmail 3434 invoked by alias); 22 Jun 2020 10:28:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: Sender: zsh-workers@zsh.org X-Seq: 46097 Received: (qmail 7812 invoked by uid 1010); 22 Jun 2020 10:28:28 -0000 X-Qmail-Scanner-Diagnostics: from mail.cock.li by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25850. spamassassin: 3.4.4. Clear:RC:0(37.120.193.124):SA:0(-1.9/5.0):. Processed in 2.568901 secs); 22 Jun 2020 10:28:28 -0000 X-Envelope-From: zsugabubus@national.shitposting.agency X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: fail (ns1.primenet.com.au: SPF record at national.shitposting.agency does not designate 37.120.193.124 as permitted sender) Date: Mon, 22 Jun 2020 12:27:38 +0200 From: zsugabubus To: Daniel Shahaf Cc: zsh-workers@zsh.org Subject: Re: Useless assignment in _rm Message-ID: <20200622102738.56fotlwrsbckxgzh@localhost> References: <20200621120913.tk5caqwb3ob2r6wt@localhost> <20200621133257.2c4b679d@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200621133257.2c4b679d@tarpaulin.shahaf.local2> On Sun, Jun 21, 2020 at 01:32:57PM +0000, Daniel Shahaf wrote: > I suppose anything that uses «*::…» or «*:::…» should verify that > CURRENT is >=1 before using it? I searched for similar assignments and queries but I could not find other place where an extra check would be needed. (“$words[CURRENT]” is safe no?, because a negative number will just index backwards so it gives the correct word; and out-of-bounds or zero just returns nothing.) > > As much as I understand, the assignment is not needed because in the > > next line the whole array will be reassigned. > > That's not quite right: the assignment uses $line. The patch causes > «rm foo» when foo and foobar both exist to complete foobar; > without the patch the completion is considered ambiguous. You are absolutely right!! -- zsugabubus diff --git a/Completion/Unix/Command/_rm b/Completion/Unix/Command/_rm index ea9190d..e66b77f 100644 --- a/Completion/Unix/Command/_rm +++ b/Completion/Unix/Command/_rm @@ -69,7 +69,7 @@ _arguments -C -s -S $opts \ case $state in (file) - line[CURRENT]=() + (( CURRENT > 0 )) && line[CURRENT]=() line=( ${line//(#m)[\[\]()\\*?#<>~\^\|]/\\$MATCH} ) _files -F line && ret=0 ;;