From 3404366b6593bbf372da35ef8c7ce6cde429cef7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Jan 2013 14:25:48 +0100 Subject: [PATCH] add more asserts --- src/buffer.cc | 5 ++++- src/dynamic_selection_list.cc | 5 +++-- src/editor.cc | 3 +++ src/selection.cc | 6 ++++-- 4 files changed, 14 insertions(+), 5 deletions(-) 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)