Skip to content

Commit 7468f09

Browse files
authored
ed: getAddr() vs maxline() (#831)
* When adding getAddr() call to edMove() I noticed getAddr() doesn't raise error for n>maxline case * This logic was only in input() before, but it seems more correct for getAddr() to check the maxline limit * Also add missing check in edMove() for stray characters leftover after calling getAddr(); the argument to m should be a single address so anything remaining is invalid input * test: 1,2m.A ---> "A" suffix invalid after "."
1 parent 01f2e73 commit 7468f09

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bin/ed

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use constant A_NOMATCH => -1;
6363
use constant A_NOPAT => -2;
6464
use constant A_PATTERN => -3;
6565
use constant A_NOMARK => -4;
66+
use constant A_RANGE => -5;
6667

6768
use constant E_ADDREXT => 'unexpected address';
6869
use constant E_ADDRBAD => 'invalid address';
@@ -240,7 +241,7 @@ sub input {
240241
} elsif ($ad == A_PATTERN) {
241242
edWarn(E_PATTERN);
242243
return;
243-
} elsif ($ad > maxline() || $ad < 0) {
244+
} elsif ($ad < 0) {
244245
edWarn(E_ADDRBAD);
245246
return;
246247
}
@@ -438,10 +439,11 @@ sub edMove {
438439
}
439440
$_ = $args[0];
440441
my $dst = getAddr();
442+
return E_SUFFBAD if m/\S/;
441443
if (defined $dst) {
442444
return E_NOMATCH if $dst == A_NOMATCH;
443445
return E_NOPAT if $dst == A_NOPAT;
444-
return E_ADDRBAD if $dst < 0 || $dst > maxline();
446+
return E_ADDRBAD if $dst < 0;
445447
} else {
446448
$dst = $CurrentLineNum;
447449
}
@@ -948,6 +950,9 @@ sub getAddr {
948950
$n = edSearch($re, $delim eq '?');
949951
$n = A_NOMATCH unless $n;
950952
}
953+
if (defined $n) {
954+
return A_RANGE if $n < 0 || $n > maxline();
955+
}
951956
return $n;
952957
}
953958

0 commit comments

Comments
 (0)