From bc9de7f88ea7a20b0324ea7430614d903134ca35 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Thu, 8 Feb 2024 04:54:49 +0800 Subject: [PATCH] ed: 1s/pat1/pat2/ incorrectly processes multiple lines (#441) * ed: 1s/pat1/pat2/ incorrectly processes multiple lines * If current line is 10, and I enter 1s/e/E/, the substitution was occurring for lines 1-10 instead of just line 1 * If I want substitution on lines 1-10 I'm supposed to type 1,10s/e/E/ * If I only want to substitute on the current line I omit the addresses and type s/e/E/ * Patch is based on existing behaviour of edPrint() * When searching for assignments of $adrs[1] I didn't find any more instances where it's set to current line * fix h command * more correct to check both addresses --- bin/ed | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/ed b/bin/ed index ceb2fc12..9667f383 100755 --- a/bin/ed +++ b/bin/ed @@ -325,7 +325,7 @@ sub edHelp { if ($toggle) { $EXTENDED_MESSAGES ^= 1; } - if ($EXTENDED_MESSAGES && defined($Error)) { + if (defined($Error) && ($EXTENDED_MESSAGES || !$toggle)) { print "$Error\n"; } } @@ -499,8 +499,12 @@ sub edSubstitute { # parse args $adrs[0] = $CurrentLineNum unless (defined($adrs[0])); - $adrs[1] = $CurrentLineNum unless (defined($adrs[1])); + $adrs[1] = $adrs[0] unless (defined $adrs[1]); + if ($adrs[0] == 0 || $adrs[1] == 0) { + edWarn(E_ADDRBAD); + return; + } unless (defined($args[0])) { edWarn(E_PATTERN); return;