From 563f62b467f339673ed4f61d8c3ee119c769a6eb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 12 Dec 2013 13:45:14 +0000 Subject: [PATCH] Fix Buffer::char_next when the line ends with an invalid utf8 sequence --- src/buffer.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/buffer.cc b/src/buffer.cc index 3f6fdadd..afc78976 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -673,6 +673,12 @@ BufferCoord Buffer::char_next(BufferCoord coord) const { auto& line = m_lines[coord.line].content; coord.column += utf8::codepoint_size(line.begin() + (int)coord.column); + // Handle invalid utf-8 + if (coord.column >= line.length()) + { + ++coord.line; + coord.column = 0; + } } else if (coord.line == m_lines.size() - 1) coord.column = m_lines.back().length();