From d7f934b7ca1b37dd5710e0b058a6ac1f4fe1c9d9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 19 Oct 2011 14:25:13 +0000 Subject: [PATCH] Buffer: iterator_at prevents getting iterators on end of line --- src/buffer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 324ecd66..cf60fa84 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -57,8 +57,9 @@ BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const if (m_lines.empty()) return begin(); - BufferPos line = Kakoune::clamp(0, m_lines.size() - 1, line_and_column.line); - BufferPos column = Kakoune::clamp(0, line_length(line), line_and_column.column); + BufferPos line = Kakoune::clamp(0, m_lines.size() - 1, line_and_column.line); + int col_max = std::max(0, line_length(line) - 1); + BufferPos column = Kakoune::clamp(0, col_max, line_and_column.column); return BufferIterator(*this, m_lines[line] + column); }