Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/nvi/dist/vi Fix screen corruption by rewriting ...



details:   https://anonhg.NetBSD.org/src/rev/3449540caf9e
branches:  trunk
changeset: 827975:3449540caf9e
user:      rin <rin%NetBSD.org@localhost>
date:      Tue Nov 21 06:35:22 2017 +0000

description:
Fix screen corruption by rewriting only a part of a multi-width character.

diffstat:

 external/bsd/nvi/dist/vi/v_txt.c |  33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diffs (85 lines):

diff -r fa9ced9d165d -r 3449540caf9e external/bsd/nvi/dist/vi/v_txt.c
--- a/external/bsd/nvi/dist/vi/v_txt.c  Tue Nov 21 03:42:39 2017 +0000
+++ b/external/bsd/nvi/dist/vi/v_txt.c  Tue Nov 21 06:35:22 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: v_txt.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
+/*     $NetBSD: v_txt.c,v 1.5 2017/11/21 06:35:22 rin Exp $ */
 /*-
  * Copyright (c) 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: v_txt.c,v 10.108 2003/07/18 21:27:42 skimo Exp  (Berkeley) Date: 2003/07/18 21:27:42 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: v_txt.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
+__RCSID("$NetBSD: v_txt.c,v 1.5 2017/11/21 06:35:22 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -2275,11 +2275,11 @@
         * The end mark may not be the same size as the current character.
         * Don't let the line shift.
         */
-       nlen = KEY_LEN(sp, ch);
+       nlen = KEY_COL(sp, ch);
        if (tp->lb[cno] == '\t')
                (void)vs_columns(sp, tp->lb, tp->lno, &cno, &olen);
        else
-               olen = KEY_LEN(sp, tp->lb[cno]);
+               olen = KEY_COL(sp, tp->lb[cno]);
 
        /*
         * If the line got longer, well, it's weird, but it's easy.  If
@@ -2299,7 +2299,19 @@
                if (tp->lb[cno] == '\t')
                        for (cno += chlen; chlen--;)
                                *p++ = ' ';
-               else
+               else if (INTISWIDE(tp->lb[cno])) {
+                       /*
+                        * Do not put the end mark on a part of a multi-width
+                        * char, which results in screen corruption.
+                        */
+                       for (; chlen >= nlen; chlen -= nlen) {
+                               cno++;
+                               *p++ = ch;
+                       }
+                       /* Paranoia: nlen is usually 1. */
+                       for (cno += chlen; chlen--;)
+                               *p++ = ' ';
+               } else
                        for (kp = KEY_NAME(sp, tp->lb[cno]),
                            cno += chlen; chlen--;)
                                *p++ = *kp++;
@@ -2457,7 +2469,7 @@
                        (void)vs_columns(sp, tp->lb, tp->lno, &cno, &nlen);
                        tp->lb[cno] = savech;
                } else
-                       nlen = KEY_LEN(sp, *chp);
+                       nlen = KEY_COL(sp, *chp);
 
                /*
                 * Eat overwrite characters until we run out of them or we've
@@ -2472,7 +2484,7 @@
                                (void)vs_columns(sp,
                                    tp->lb, tp->lno, &cno, &olen);
                        else
-                               olen = KEY_LEN(sp, tp->lb[cno]);
+                               olen = KEY_COL(sp, tp->lb[cno]);
 
                        if (olen == nlen) {
                                nlen = 0;
@@ -2491,7 +2503,12 @@
 
                                tp->len += chlen;
                                tp->owrite += chlen;
-                               if (tp->lb[cno] == '\t')
+                               /*
+                                * Do not rewrite a part of a multi-width char,
+                                * which results in screen corruption.
+                                */
+                               if (tp->lb[cno] == '\t'
+                                   || INTISWIDE(tp->lb[cno]))
                                        for (p = tp->lb + cno + 1; chlen--;)
                                                *p++ = ' ';
                                else



Home | Main Index | Thread Index | Old Index