summaryrefslogtreecommitdiffstats
path: root/tty-keys.c
diff options
context:
space:
mode:
authornicm <nicm>2016-03-02 15:36:02 +0000
committernicm <nicm>2016-03-02 15:36:02 +0000
commitb8a102d26f41e57b94359627a4df8f22af10c6fa (patch)
tree43730f925370a2d77bf64e817cb77bfaf4849dc5 /tty-keys.c
parentd980d965ddb6165bd801351892fed2497204a279 (diff)
Handle wcwidth() and mbtowc() failures in better style and drop
characters where we can't find the width (wcwidth() fails) on input, the same as we drop invalid UTF-8. Suggested by schwarze@.
Diffstat (limited to 'tty-keys.c')
-rw-r--r--tty-keys.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/tty-keys.c b/tty-keys.c
index 2b998778..105f99f7 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -477,6 +477,7 @@ tty_keys_next(struct tty *tty)
struct utf8_data ud;
enum utf8_state more;
u_int i;
+ wchar_t wc;
/* Get key buffer. */
buf = EVBUFFER_DATA(tty->event->input);
@@ -552,7 +553,11 @@ first_key:
more = utf8_append(&ud, (u_char)buf[i]);
if (more != UTF8_DONE)
goto discard_key;
- key = utf8_combine(&ud);
+
+ if (utf8_combine(&ud, &wc) != UTF8_DONE)
+ goto discard_key;
+ key = wc;
+
log_debug("UTF-8 key %.*s %#llx", (int)size, buf, key);
goto complete_key;
}