diff --git a/src/buffer.cc b/src/buffer.cc index 92089e83..d384f3bb 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -245,7 +245,8 @@ void Buffer::check_invariant() const void Buffer::do_insert(const BufferIterator& pos, const String& content) { - assert(pos.is_end() or utf8::is_character_start(pos)); + assert(pos.is_valid() and (pos.is_end() or utf8::is_character_start(pos))); + assert(not contains(content, '\0')); ++m_timestamp; ByteCount offset = pos.offset(); @@ -322,6 +323,8 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content) void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end) { + assert(begin.is_valid()); + assert(end.is_valid()); assert(utf8::is_character_start(begin) and (end.is_end() or utf8::is_character_start(end))); ++m_timestamp; diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index d7eb5beb..90067505 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -64,7 +64,10 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections) void DynamicSelectionList::check_invariant() const { for (auto& sel : *this) + { assert(m_buffer == &sel.buffer()); + sel.check_invariant(); + } } void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end) @@ -73,7 +76,6 @@ void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIt { sel.first().on_insert(begin.coord(), end.coord()); sel.last().on_insert(begin.coord(), end.coord()); - sel.check_invariant(); } } @@ -83,7 +85,6 @@ void DynamicSelectionList::on_erase(const BufferIterator& begin, const BufferIte { sel.first().on_erase(begin.coord(), end.coord()); sel.last().on_erase(begin.coord(), end.coord()); - sel.check_invariant(); } } diff --git a/src/editor.cc b/src/editor.cc index 9fcc0f15..4bb9f464 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -334,12 +334,15 @@ public: void on_insert(const BufferIterator& begin, const BufferIterator& end) { + assert(begin.is_valid()); + assert(end.is_valid()); m_first = begin; m_last = utf8::previous(end); } void on_erase(const BufferIterator& begin, const BufferIterator& end) { + assert(begin.is_valid()); m_first = begin; if (m_first >= m_buffer.end()) m_first = utf8::previous(m_buffer.end()); diff --git a/src/selection.cc b/src/selection.cc index bc156f26..77511c00 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -26,8 +26,10 @@ BufferIterator Range::end() const void Range::check_invariant() const { - assert(utf8::is_character_start(first())); - assert(utf8::is_character_start(last())); + assert(m_first.is_valid()); + assert(m_last.is_valid()); + assert(utf8::is_character_start(m_first)); + assert(utf8::is_character_start(m_last)); } static void avoid_eol(BufferIterator& it)