aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-10 18:11:30 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-10 18:11:30 -0700
commit6e4a45c0050ed8eacdd2426b971e263cbdcca0ae (patch)
tree62f0a4337cf050e1df8b4ed62ecf978c0c10a7a7
parent3abd3dba424450401ca0bb34c043d0331f1c1abe (diff)
downloaduemacs-6e4a45c0050ed8eacdd2426b971e263cbdcca0ae.tar.gz
character input: make sure we have enough bytes for a full utf8 character
.. but we do have that 0.1s delay, so if somebody feeds us non-utf8 sequences, we won't delay forever. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--posix.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/posix.c b/posix.c
index e6ebc83..97edd9f 100644
--- a/posix.c
+++ b/posix.c
@@ -153,7 +153,7 @@ int ttgetc(void)
static char buffer[32];
static int pending;
unicode_t c;
- int count, bytes = 1;
+ int count, bytes = 1, expected;
count = pending;
if (!count) {
@@ -167,8 +167,25 @@ int ttgetc(void)
if (c >= 32 && c < 128)
goto done;
+ /*
+ * Lazy. We don't bother calculating the exact
+ * expected length. We want at least two characters
+ * for the special character case (ESC+[) and for
+ * the normal short UTF8 sequence that starts with
+ * the 110xxxxx pattern.
+ *
+ * But if we have any of the other patterns, just
+ * try to get more characters. At worst, that will
+ * just result in a barely perceptible 0.1 second
+ * delay for some *very* unusual utf8 character
+ * input.
+ */
+ expected = 2;
+ if ((c & 0xe0) == 0xe0)
+ expected = 6;
+
/* Special character - try to fill buffer */
- if (count == 1) {
+ if (count < expected) {
int n;
ntermios.c_cc[VMIN] = 0;
ntermios.c_cc[VTIME] = 1; /* A .1 second lag */