aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-03 21:10:14 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-03 21:10:14 +0000
commita2f3d807f8e7c2c1f4421494eede16f04944180c (patch)
tree51c1772d86da69dbb2096766344df87b21c1afed /termkey.c
parent76147e92d4bd12c27ef56d8ab9b1203ee3eeb927 (diff)
downloadtermo-a2f3d807f8e7c2c1f4421494eede16f04944180c.tar.gz
termo-a2f3d807f8e7c2c1f4421494eede16f04944180c.tar.xz
termo-a2f3d807f8e7c2c1f4421494eede16f04944180c.zip
Better handling of incomplete UTF-8 sequences - just emit a UTF8_INVALID if waittime is up
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/termkey.c b/termkey.c
index 7b42d14..c730bda 100644
--- a/termkey.c
+++ b/termkey.c
@@ -440,8 +440,19 @@ static termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force)
return TERMKEY_RES_KEY;
}
- if(tk->buffcount < nbytes)
- return tk->waittime ? TERMKEY_RES_AGAIN : TERMKEY_RES_NONE;
+ if(tk->buffcount < nbytes) {
+ if(!force)
+ return TERMKEY_RES_AGAIN;
+
+ /* There weren't enough bytes for a complete UTF-8 sequence but caller
+ * demands an answer. About the best thing we can do here is eat as many
+ * bytes as we have, and emit a UTF8_INVALID. If the remaining bytes
+ * arrive later, they'll be invalid too.
+ */
+ (*tk->method.emit_codepoint)(tk, UTF8_INVALID, key);
+ (*tk->method.eat_bytes)(tk, tk->buffcount);
+ return TERMKEY_RES_KEY;
+ }
for(int b = 1; b < nbytes; b++) {
unsigned char cb = CHARAT(b);