Hi,
Another UTF-8 related bug reported by tb@. How to re-produce:

1. Enable vi mode:

   $ set -o vi

2. Input the following characters: öa

3. Press escape and then x twice.

4. An invalid UTF-8 character is displayed.

Similar to one of my previous diffs, looks like the column counter is
wrong. The diff below fixes the problem and includes a regression test.
I'm not running vi mode myself so further testing would be appreciated.

Index: bin/ksh/vi.c
===================================================================
RCS file: /cvs/src/bin/ksh/vi.c,v
retrieving revision 1.44
diff -u -p -r1.44 vi.c
--- bin/ksh/vi.c        17 Oct 2016 18:39:43 -0000      1.44
+++ bin/ksh/vi.c        19 May 2017 10:47:44 -0000
@@ -1155,7 +1155,9 @@ vi_cmd(int argcnt, const char *cmd)
                        break;
                }
                if (insert == 0 && es->cursor != 0 && es->cursor >= es->linelen)
-                       es->cursor--;
+                       while (es->cursor > 0)
+                               if (!isu8cont(es->cbuf[--es->cursor]))
+                                       break;
        }
        return 0;
 }
Index: regress/bin/ksh/vi/vi.sh
===================================================================
RCS file: /cvs/src/regress/bin/ksh/vi/vi.sh,v
retrieving revision 1.1
diff -u -p -r1.1 vi.sh
--- regress/bin/ksh/vi/vi.sh    12 Jan 2016 09:00:39 -0000      1.1
+++ regress/bin/ksh/vi/vi.sh    19 May 2017 10:47:44 -0000
@@ -168,6 +168,7 @@ testseq "abcd\00332X" " $ abcd\b\b\bd  \
 # x: Delete character.
 # |: Move to column.
 testseq "abcd\00332|2x" " $ abcd\b\b\bd  \b\b\b\r\nad"
+testseq "\0303\0266a\0033xx" " $ \0303\0266a\b \b\b  \b\b\r"
 
 # Y: Yank to end of line.
 testseq "abcd\0033hYp" " $ abcd\b\bccdd\b\b\r\nabccdd"

Reply via email to