diff options
author | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-11-17 15:08:53 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-12-19 23:16:02 +0100 |
commit | f26eb796e228cbec754e9e24545f5b0a8a50aac1 (patch) | |
tree | 3b20b3bc5adf684971fae399539e1b225d632439 | |
parent | 7d49fedc86bec300d22f44f93ec95825320dd1c1 (diff) | |
download | busybox-w32-f26eb796e228cbec754e9e24545f5b0a8a50aac1.tar.gz busybox-w32-f26eb796e228cbec754e9e24545f5b0a8a50aac1.tar.bz2 busybox-w32-f26eb796e228cbec754e9e24545f5b0a8a50aac1.zip |
ed: fix current line number for file passed via the command-line
POSIX.1-2008 mandates the following regarding the file command-line
argument:
If the file argument is given, ed shall simulate an e command
on the file named by the pathname […]
The specification for the e command mandates the following behaviour
regarding the current line number in POSIX.1-2008:
The current line number shall be set to the address of the last
line of the buffer.
However, without this commit, busybox ed will set the current line
number to 1 if a file is given on the command-line and this file is not
empty (lastNum != 0). This is incorrect and fixed in this commit by not
modifying the current line number in ed_main(). As such, the current
line number will be zero for empty files and otherwise be set to the
address of the last line of the buffer.
function old new delta
ed_main 144 128 -16
Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/ed.c | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/editors/ed.c b/editors/ed.c index 18faba5a4..fed10c470 100644 --- a/editors/ed.c +++ b/editors/ed.c | |||
@@ -1016,8 +1016,6 @@ int ed_main(int argc UNUSED_PARAM, char **argv) | |||
1016 | if (!readLines(fileName, 1)) { | 1016 | if (!readLines(fileName, 1)) { |
1017 | return EXIT_SUCCESS; | 1017 | return EXIT_SUCCESS; |
1018 | } | 1018 | } |
1019 | if (lastNum) | ||
1020 | setCurNum(1); | ||
1021 | dirty = FALSE; | 1019 | dirty = FALSE; |
1022 | } | 1020 | } |
1023 | 1021 | ||