From 5b4ef23b9d8fcc516b90690a12e8403a17364ccc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 27 Jun 2013 23:49:34 +0200 Subject: [PATCH] more tolerant Buffer::string --- src/buffer.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 26155bda..c8853708 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -129,15 +129,15 @@ LineCount Buffer::line_count() const String Buffer::string(const BufferCoord& begin, const BufferCoord& end) const { String res; - for (LineCount line = begin.line; line <= end.line; ++line) + for (auto line = begin.line; line <= end.line and line < line_count(); ++line) { - ByteCount start = 0; - if (line == begin.line) - start = begin.column; - ByteCount count = -1; - if (line == end.line) - count = end.column - start; - res += m_lines[line].content.substr(start, count); + ByteCount start = 0; + if (line == begin.line) + start = begin.column; + ByteCount count = -1; + if (line == end.line) + count = end.column - start; + res += m_lines[line].content.substr(start, count); } return res; }