diff options
| author | Olivier Perret <Olivier.Perret@mailbox.org> | 2017-03-03 13:44:09 +0100 |
|---|---|---|
| committer | Olivier Perret <Olivier.Perret@mailbox.org> | 2017-03-03 13:50:00 +0100 |
| commit | 033b259e5b3848e8ed153ae6fd1423571b332f25 (patch) | |
| tree | 5cba3f48080a4b4f1809b564c83260f96113eee0 /src/normal.cc | |
| parent | eace7e04246c6b56aed1edd78c3f8c9fb7cf4853 (diff) | |
<space>, <a-space>: throw on invalid preconditions
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/normal.cc b/src/normal.cc index 3f816b02..6410a2aa 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1654,8 +1654,9 @@ void keep_selection(Context& context, NormalParams p) { auto& selections = context.selections(); const int index = p.count ? p.count-1 : selections.main_index(); - if (index < selections.size()) - selections = SelectionList{ selections.buffer(), std::move(selections[index]) }; + if (index >= selections.size()) + throw runtime_error("invalid selection index"); + selections = SelectionList{ selections.buffer(), std::move(selections[index]) }; selections.check_invariant(); } @@ -1663,13 +1664,14 @@ void remove_selection(Context& context, NormalParams p) { auto& selections = context.selections(); const int index = p.count ? p.count-1 : selections.main_index(); - if (selections.size() > 1 and index < selections.size()) - { - selections.remove(index); - size_t main_index = selections.main_index(); - if (index < main_index or main_index == selections.size()) - selections.set_main_index(main_index - 1); - } + if (index >= selections.size()) + throw runtime_error("invalid selection index"); + if (selections.size() == 1) + throw runtime_error("no selections remaining"); + selections.remove(index); + size_t main_index = selections.main_index(); + if (index < main_index or main_index == selections.size()) + selections.set_main_index(main_index - 1); selections.check_invariant(); } |
