Replace character with U+FFFD if wcwidth() is -1
authorczarkoff@gmail.com <czarkoff@gmail.com>
Tue, 28 Oct 2014 11:55:28 +0000 (12:55 +0100)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Mon, 3 Nov 2014 21:52:58 +0000 (22:52 +0100)
Helpful when new Unicode codepoints are not recognized by libc.

st.c

diff --git a/st.c b/st.c
index 23dd7f1..ad52280 100644 (file)
--- a/st.c
+++ b/st.c
@@ -2576,7 +2576,10 @@ tputc(char *c, int len) {
                unicodep = ascii = *c;
        } else {
                utf8decode(c, &unicodep, UTF_SIZ);
-               width = wcwidth(unicodep);
+               if ((width = wcwidth(unicodep)) == -1) {
+                       c = "\357\277\275";     /* UTF_INVALID */
+                       width = 1;
+               }
                control = ISCONTROLC1(unicodep);
                ascii = unicodep;
        }