diff options
author | Dan Harnett <danh@cvs.openbsd.org> | 2005-01-27 16:25:07 +0000 |
---|---|---|
committer | Dan Harnett <danh@cvs.openbsd.org> | 2005-01-27 16:25:07 +0000 |
commit | 8114fbee1d923edaabd40b9013b87e6212a3782e (patch) | |
tree | 14c9631bf55b1f0c7834d4a4a6fbfbfb7b66c20f /bin/ksh/vi.c | |
parent | db2e8509fd98c86caac96035652519f2d162f283 (diff) |
fix some vi-mode bugs spotted by jmc@
tested by jmc@, ok otto@
Diffstat (limited to 'bin/ksh/vi.c')
-rw-r--r-- | bin/ksh/vi.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index 05077d50bba..cced6365236 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.18 2004/12/22 17:14:34 millert Exp $ */ +/* $OpenBSD: vi.c,v 1.19 2005/01/27 16:25:06 danh Exp $ */ /* * vi command editing @@ -855,7 +855,7 @@ vi_cmd(int argcnt, const char *cmd) case 'g': if (!argcnt) - argcnt = hlast + 1; + argcnt = hlast; /* fall through */ case 'G': if (!argcnt) @@ -909,8 +909,15 @@ vi_cmd(int argcnt, const char *cmd) modified = 1; hnum = hlast; if (cmd[1] == 0) vi_error(); - else - es->cbuf[es->cursor] = cmd[1]; + else { + int n; + + if (es->cursor + argcnt > es->linelen) + return -1; + for (n = 0; n < argcnt; ++n) + es->cbuf[es->cursor + n] = cmd[1]; + es->cursor += n - 1; + } break; case 'R': @@ -929,7 +936,7 @@ vi_cmd(int argcnt, const char *cmd) break; case 'v': - if (es->linelen == 0) + if (es->linelen == 0 && argcnt == 0) return -1; if (!argcnt) { if (modified) { |