summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2020-05-26 08:49:36 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-05-26 08:49:36 +0100
commitd73fcfc176b4032dd69d88e0bdef3565bbcb3eb4 (patch)
tree601ec3884c18e235eb6e4ceb51560c9357384ad9 /utf8.c
parent967e5f8be3d89c6b604484d3b7b2a1ff25db06a5 (diff)
Put the fix back for wcwidth() failing.
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/utf8.c b/utf8.c
index 353c90ba..9e727baa 100644
--- a/utf8.c
+++ b/utf8.c
@@ -244,12 +244,25 @@ utf8_width(struct utf8_data *ud, int *width)
return (UTF8_ERROR);
}
*width = wcwidth(wc);
- if (*width < 0 || *width > 0xff) {
- log_debug("UTF-8 %.*s, wcwidth() %d", (int)ud->size, ud->data,
- *width);
- return (UTF8_ERROR);
+ if (*width >= 0 && *width <= 0xff)
+ return (UTF8_DONE);
+ log_debug("UTF-8 %.*s, wcwidth() %d", (int)ud->size, ud->data, *width);
+
+#ifndef __OpenBSD__
+ /*
+ * Many platforms (particularly and inevitably OS X) have no width for
+ * relatively common characters (wcwidth() returns -1); assume width 1
+ * in this case. This will be wrong for genuinely nonprintable
+ * characters, but they should be rare. We may pass through stuff that
+ * ideally we would block, but this is no worse than sending the same
+ * to the terminal without tmux.
+ */
+ if (*width < 0) {
+ *width = 1;
+ return (UTF8_DONE);
}
- return (UTF8_DONE);
+#endif
+ return (UTF8_ERROR);
}
/*