aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroni-link <knil.ino@gmail.com>2015-07-06 21:03:20 +0200
committeroni-link <knil.ino@gmail.com>2015-07-07 16:58:10 +0200
commitb165145084ab2cf5671af07944bc8b353c21ef95 (patch)
tree4699529fd3f9528de84f82261f5f8edd643e2719 /src
parent3955ffa3051076926c904f2e05a9057aac7ea936 (diff)
downloadrneovim-b165145084ab2cf5671af07944bc8b353c21ef95.tar.gz
rneovim-b165145084ab2cf5671af07944bc8b353c21ef95.tar.bz2
rneovim-b165145084ab2cf5671af07944bc8b353c21ef95.zip
rbuffer: Fix for problems with escape input sequences.
If at least two escape sequences were read, the beginning of the second sequence would be off by one and the sequence would be misinterpreted. An escape sequence could be split in two parts and be misinterpreted, when saved in a ring buffer with wrap around. Fixes #2936
Diffstat (limited to 'src')
-rw-r--r--src/nvim/rbuffer.c9
-rw-r--r--src/nvim/tui/term_input.inl5
2 files changed, 14 insertions, 0 deletions
diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c
index 9cf681585b..0a04ba1954 100644
--- a/src/nvim/rbuffer.c
+++ b/src/nvim/rbuffer.c
@@ -69,6 +69,15 @@ char *rbuffer_write_ptr(RBuffer *buf, size_t *write_count) FUNC_ATTR_NONNULL_ALL
return buf->write_ptr;
}
+// Set read and write pointer for an empty RBuffer to the beginning of the
+// buffer.
+void rbuffer_reset(RBuffer *buf) FUNC_ATTR_NONNULL_ALL
+{
+ if (buf->size == 0) {
+ buf->write_ptr = buf->read_ptr = buf->start_ptr;
+ }
+}
+
/// Adjust `rbuffer` write pointer to reflect produced data. This is called
/// automatically by `rbuffer_write`, but when using `rbuffer_write_ptr`
/// directly, this needs to called after the data was copied to the internal
diff --git a/src/nvim/tui/term_input.inl b/src/nvim/tui/term_input.inl
index 451ac195f2..efdcf0a41e 100644
--- a/src/nvim/tui/term_input.inl
+++ b/src/nvim/tui/term_input.inl
@@ -243,6 +243,7 @@ static void read_cb(RStream *rstream, RBuffer *buf, void *data, bool eof)
RBUFFER_EACH(input->read_buffer, c, i) {
count = i + 1;
if (c == '\x1b' && count > 1) {
+ count--;
break;
}
}
@@ -262,6 +263,10 @@ static void read_cb(RStream *rstream, RBuffer *buf, void *data, bool eof)
}
}
} while (rbuffer_size(input->read_buffer));
+
+ // Make sure the next input escape sequence fits into the ring buffer
+ // without wrap around, otherwise it could be misinterpreted.
+ rbuffer_reset(input->read_buffer);
}
static TermInput *term_input_new(void)