diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-10-28 21:55:08 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-10-28 21:55:08 +0000 |
| commit | d29419bcd69432aded1df73cb74853db86daf20d (patch) | |
| tree | b1dc9bfacf12ef8c7a2669567eb5c95d159f742a /src | |
| parent | 62f56378c949a57ddd08b4d4eacf898758fcb03e (diff) | |
Fix invalid memory access when applying modifications on an empty buffer
That can happen when undoing/redoing accross a buffer reload
boundary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.cc | 4 | ||||
| -rw-r--r-- | src/buffer.inl.hh | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 81804c79..0b0dca1e 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -351,7 +351,9 @@ void Buffer::apply_modification(const Modification& modification) kak_assert(is_valid(coord)); // in modifications, end coords should be {line_count(), 0} - kak_assert(coord != ByteCoord(line_count()-1, m_lines.back().length())); + kak_assert((m_lines.empty() and coord == ByteCoord{0,0} ) or + coord != ByteCoord(line_count()-1, m_lines.back().length())); + switch (modification.type) { case Modification::Insert: diff --git a/src/buffer.inl.hh b/src/buffer.inl.hh index 0e82b7a9..7b09f1a4 100644 --- a/src/buffer.inl.hh +++ b/src/buffer.inl.hh @@ -68,7 +68,7 @@ inline bool Buffer::is_valid(ByteCoord c) const inline bool Buffer::is_end(ByteCoord c) const { - return c >= ByteCoord{line_count() - 1, m_lines.back().length()}; + return c >= end_coord(); } inline BufferIterator Buffer::begin() const @@ -78,9 +78,7 @@ inline BufferIterator Buffer::begin() const inline BufferIterator Buffer::end() const { - if (m_lines.empty()) - return BufferIterator(*this, { 0_line, 0 }); - return BufferIterator(*this, { line_count() - 1, m_lines.back().length() }); + return BufferIterator{*this, end_coord()}; } [[gnu::always_inline]] @@ -107,6 +105,8 @@ inline ByteCoord Buffer::back_coord() const inline ByteCoord Buffer::end_coord() const { + if (m_lines.empty()) + return { 0_line, 0 }; return { line_count() - 1, m_lines.back().length() }; } |
