diff options
author | Ron Yorston <rmy@pobox.com> | 2021-04-15 12:02:43 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-15 13:09:12 +0200 |
commit | 38ae0f3e3e9490c5b8cc3b917c2d896404afddbe (patch) | |
tree | dce724c5a0c89ecf31028e0acf7511e7ad326723 | |
parent | 033fa3d5c65958a89fee155208ce8ac7f9049fcd (diff) | |
download | busybox-w32-38ae0f3e3e9490c5b8cc3b917c2d896404afddbe.tar.gz busybox-w32-38ae0f3e3e9490c5b8cc3b917c2d896404afddbe.tar.bz2 busybox-w32-38ae0f3e3e9490c5b8cc3b917c2d896404afddbe.zip |
vi: reset command count when specifying '0' range
Since commit a54450248 (vi: allow the '.' command to have a
repetition count) using '0' to specify a range doesn't work with
a non-zero repeat count, e.g. '1d0'. Users wouldn't normally try
to do that but the '.' command does.
Add a special case in get_motion_char() to handle this.
function old new delta
find_range 737 746 +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/editors/vi.c b/editors/vi.c index d37357edd..d20481fbd 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -1128,11 +1128,16 @@ static int get_motion_char(void) | |||
1128 | int c, cnt; | 1128 | int c, cnt; |
1129 | 1129 | ||
1130 | c = get_one_char(); | 1130 | c = get_one_char(); |
1131 | if (c != '0' && isdigit(c)) { | 1131 | if (isdigit(c)) { |
1132 | // get any non-zero motion count | 1132 | if (c != '0') { |
1133 | for (cnt = 0; isdigit(c); c = get_one_char()) | 1133 | // get any non-zero motion count |
1134 | cnt = cnt * 10 + (c - '0'); | 1134 | for (cnt = 0; isdigit(c); c = get_one_char()) |
1135 | cmdcnt = (cmdcnt ?: 1) * cnt; | 1135 | cnt = cnt * 10 + (c - '0'); |
1136 | cmdcnt = (cmdcnt ?: 1) * cnt; | ||
1137 | } else { | ||
1138 | // ensure standalone '0' works | ||
1139 | cmdcnt = 0; | ||
1140 | } | ||
1136 | } | 1141 | } |
1137 | 1142 | ||
1138 | return c; | 1143 | return c; |