about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2017-05-10 22:18:16 +0000
committerThomas E. Dickey <dickey@invisible-island.net>2017-05-10 22:18:16 +0000
commitd8726c3462b40ad0e357e8e5472c84573d3cfd06 (patch)
tree068b59449e9a17b31d01ded5699454c2859302af
parent79de0ed75de47a025bfacb8c491cb5dcb9144c36 (diff)
downloadlynx-snapshots-d8726c3462b40ad0e357e8e5472c84573d3cfd06.tar.gz
snapshot of project "lynx", label v2-8-9dev_13b
-rw-r--r--CHANGES7
-rw-r--r--src/LYStrings.c37
2 files changed, 41 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index efa373df..a52c7e6a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,12 @@
--- $LynxId: CHANGES,v 1.891 2017/04/30 17:54:33 tom Exp $
+-- $LynxId: CHANGES,v 1.892 2017/05/10 22:18:16 tom Exp $
 ===============================================================================
 Changes since Lynx 2.8 release
 ===============================================================================
 
-2017-04-30 (2.8.9dev.14)
+2017-05-10 (2.8.9dev.14)
+* amend fix for Debian #841155, adding check for complete multibyte strings to
+  decide when the cell-limit has been met (Debian #862148) -TD
+
 * compiler-warning fixes for c99 on OSX -TD
 
 2017-04-29 (2.8.9dev.13)
diff --git a/src/LYStrings.c b/src/LYStrings.c
index 9f0ef0f1..d063a171 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYStrings.c,v 1.267 2017/04/29 14:38:32 tom Exp $ */
+/* $LynxId: LYStrings.c,v 1.268 2017/05/10 22:11:33 tom Exp $ */
 #include <HTUtils.h>
 #include <HTCJK.h>
 #include <UCAux.h>
@@ -3069,6 +3069,39 @@ static int mbcs_glyphs(char *s, int len)
 }
 
 /*
+ * Check if there are no continuation bytes in the multibyte (sub)string of
+ * length len.
+ */
+static int mbcs_valid(char *s, int len, int limit)
+{
+    int i;
+    int result = FALSE;
+
+    if (IS_UTF8_TTY) {
+	for (i = 0; s[i] && i < limit; i++) {
+	    if (!IS_UTF8_EXTRA(s[i])) {
+		if ((i + 1) == len) {
+		    result = TRUE;
+		    break;
+		}
+	    }
+	}
+    } else if (IS_CJK_TTY) {
+	for (i = 0; s[i] && i < limit; i++) {
+	    if (!is8bits(s[i])) {
+		if ((i + 1) == len) {
+		    result = TRUE;
+		    break;
+		}
+	    }
+	}
+    } else {
+	result = TRUE;
+    }
+    return result;
+}
+
+/*
  * Calculates offset in bytes of a glyph at cell position pos.
  */
 static int mbcs_skip(char *s, int pos)
@@ -3116,6 +3149,8 @@ static int cell2char(char *s, int cells)
 		    break;
 		/* the best solution is the one with the most bytes */
 		best = pos;
+		if (mbcs_valid(s, pos, len))
+		    break;
 	    }
 	}
 	if (best >= 0)