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 Make sure that every wide char occupie...



details:   https://anonhg.NetBSD.org/src/rev/53969b782985
branches:  trunk
changeset: 319560:53969b782985
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Jun 03 08:08:36 2018 +0000

description:
Make sure that every wide char occupies at least one display width:
  - Replace non-printable multibyte char with ?-symbol.
  - Put space before non-spacing char.

Fix problems reported in PR bin/53164 and
PR bin/53323, that are because we did not take into account non-printable
multibyte char of wctob(wc) == EOF && wcwidth(wc) == -1.

diffstat:

 external/bsd/nvi/dist/common/conv.h    |  15 ++++++++++-----
 external/bsd/nvi/dist/vi/vs_line.c     |  23 ++++++++++++++++++-----
 external/bsd/nvi/dist/vi/vs_relative.c |   8 ++++----
 3 files changed, 32 insertions(+), 14 deletions(-)

diffs (104 lines):

diff -r 98ad703fdbc9 -r 53969b782985 external/bsd/nvi/dist/common/conv.h
--- a/external/bsd/nvi/dist/common/conv.h       Sun Jun 03 07:54:51 2018 +0000
+++ b/external/bsd/nvi/dist/common/conv.h       Sun Jun 03 08:08:36 2018 +0000
@@ -1,9 +1,14 @@
-/*     $NetBSD: conv.h,v 1.2 2013/11/22 15:52:05 christos Exp $        */
+/*     $NetBSD: conv.h,v 1.3 2018/06/03 08:08:36 rin Exp $     */
+
+/*
+ * We ensure that every wide char occupies at least one display width.
+ * See vs_line.c for more details.
+ */
+#define WIDE_COL(sp, ch)                                               \
+       (CHAR_WIDTH(sp, ch) >= 0 ? CHAR_WIDTH(sp, ch) : 1)
+
 #define KEY_COL(sp, ch)                                                        \
-       (INTISWIDE(ch) ?                                                \
-           (CHAR_WIDTH(sp, ch) >= 0) ?                                 \
-              (size_t)CHAR_WIDTH(sp, ch) : 1 /* extra space */         \
-           : KEY_LEN(sp,ch))
+       (INTISWIDE(ch) ? (size_t)WIDE_COL(sp, ch) : KEY_LEN(sp, ch))
 
 struct _conv_win {
     void    *bp1;
diff -r 98ad703fdbc9 -r 53969b782985 external/bsd/nvi/dist/vi/vs_line.c
--- a/external/bsd/nvi/dist/vi/vs_line.c        Sun Jun 03 07:54:51 2018 +0000
+++ b/external/bsd/nvi/dist/vi/vs_line.c        Sun Jun 03 08:08:36 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vs_line.c,v 1.4 2017/11/10 14:44:13 rin Exp $ */
+/*     $NetBSD: vs_line.c,v 1.5 2018/06/03 08:08:37 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: vs_line.c,v 10.38 2002/01/19 21:59:07 skimo Exp  (Berkeley) Date: 2002/01/19 21:59:07 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: vs_line.c,v 1.4 2017/11/10 14:44:13 rin Exp $");
+__RCSID("$NetBSD: vs_line.c,v 1.5 2018/06/03 08:08:37 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -497,10 +497,23 @@
 
                        /* XXXX this needs some rethinking */
                        if (INTISWIDE(ch)) {
-                               /* Put a space before non-spacing char. */
-                               if (CHAR_WIDTH(sp, ch) <= 0)
+                               /*
+                                * We ensure that every wide char occupies at
+                                * least one display width, as noted in conv.h:
+                                *   - Replace non-printable char with ?-symbol.
+                                *   - Put space before non-spacing char.
+                                */
+                               switch (CHAR_WIDTH(sp, ch)) {
+                               case -1:
+                                       *cbp++ = L('?');
+                                       break;
+                               case 0:
                                        *cbp++ = L(' ');
-                               *cbp++ = ch;
+                                       /* FALLTHROUGH */
+                               default:
+                                       *cbp++ = ch;
+                                       break;
+                               }
                        } else
                                for (kp = KEY_NAME(sp, ch) + offset_in_char; 
                                     chlen--;)
diff -r 98ad703fdbc9 -r 53969b782985 external/bsd/nvi/dist/vi/vs_relative.c
--- a/external/bsd/nvi/dist/vi/vs_relative.c    Sun Jun 03 07:54:51 2018 +0000
+++ b/external/bsd/nvi/dist/vi/vs_relative.c    Sun Jun 03 08:08:36 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vs_relative.c,v 1.4 2017/11/10 14:44:13 rin Exp $ */
+/*     $NetBSD: vs_relative.c,v 1.5 2018/06/03 08:08:37 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: vs_relative.c,v 10.18 2001/07/08 13:02:48 skimo Exp  (Berkeley) Date: 2001/07/08 13:02:48 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: vs_relative.c,v 1.4 2017/11/10 14:44:13 rin Exp $");
+__RCSID("$NetBSD: vs_relative.c,v 1.5 2018/06/03 08:08:37 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -178,7 +178,7 @@
                        }
 
                        /* multibyte case */
-                       chlen = CHAR_WIDTH(sp, ch);
+                       chlen = WIDE_COL(sp, ch);
                        last = scno;
                        scno += chlen;
                        len--;
@@ -216,7 +216,7 @@
                        }
 
                        /* multibyte case */
-                       chlen = CHAR_WIDTH(sp, ch);
+                       chlen = WIDE_COL(sp, ch);
                        last = scno;
                        scno += chlen;
                        p++;



Home | Main Index | Thread Index | Old Index