Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ed: getAddr() vs maxline() #831

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use constant A_NOMATCH => -1;
use constant A_NOPAT => -2;
use constant A_PATTERN => -3;
use constant A_NOMARK => -4;
use constant A_RANGE => -5;

use constant E_ADDREXT => 'unexpected address';
use constant E_ADDRBAD => 'invalid address';
Expand Down Expand Up @@ -240,7 +241,7 @@ sub input {
} elsif ($ad == A_PATTERN) {
edWarn(E_PATTERN);
return;
} elsif ($ad > maxline() || $ad < 0) {
} elsif ($ad < 0) {
edWarn(E_ADDRBAD);
return;
}
Expand Down Expand Up @@ -438,10 +439,11 @@ sub edMove {
}
$_ = $args[0];
my $dst = getAddr();
return E_SUFFBAD if m/\S/;
if (defined $dst) {
return E_NOMATCH if $dst == A_NOMATCH;
return E_NOPAT if $dst == A_NOPAT;
return E_ADDRBAD if $dst < 0 || $dst > maxline();
return E_ADDRBAD if $dst < 0;
} else {
$dst = $CurrentLineNum;
}
Expand Down Expand Up @@ -948,6 +950,9 @@ sub getAddr {
$n = edSearch($re, $delim eq '?');
$n = A_NOMATCH unless $n;
}
if (defined $n) {
return A_RANGE if $n < 0 || $n > maxline();
}
return $n;
}

Expand Down
Loading