diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-06-04 14:04:52 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-06-04 14:21:07 +0200 |
| commit | cc70e3ed708e231e581dfba94ada9fe7d7cad89c (patch) | |
| tree | dd80efd1b8fa3cb101c3083f4b135556a4d157ff /src | |
| parent | 5c2e3b25facf878cafff7499d901de27a27645ff (diff) | |
selectors.cc: avoid dereferencing buffer end
Diffstat (limited to 'src')
| -rw-r--r-- | src/selectors.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/selectors.cc b/src/selectors.cc index c2e7e62f..c9629e8b 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -86,11 +86,15 @@ template<bool punctuation_is_word> Selection select_to_next_word(const Buffer& buffer, const Selection& selection) { Utf8Iterator begin = buffer.iterator_at(selection.last()); + if (is_end(begin+1)) + return selection; if (categorize<punctuation_is_word>(*begin) != categorize<punctuation_is_word>(*(begin+1))) ++begin; skip_while(begin, is_eol); + if (is_end(begin)) + return selection; Utf8Iterator end = begin+1; if (not punctuation_is_word and is_punctuation(*begin)) @@ -109,11 +113,15 @@ template<bool punctuation_is_word> Selection select_to_next_word_end(const Buffer& buffer, const Selection& selection) { Utf8Iterator begin = buffer.iterator_at(selection.last()); + if (is_end(begin+1)) + return selection; if (categorize<punctuation_is_word>(*begin) != categorize<punctuation_is_word>(*(begin+1))) ++begin; skip_while(begin, is_eol); + if (is_end(begin)) + return selection; Utf8Iterator end = begin; skip_while(end, is_blank); @@ -131,7 +139,8 @@ template<bool punctuation_is_word> Selection select_to_previous_word(const Buffer& buffer, const Selection& selection) { Utf8Iterator begin = buffer.iterator_at(selection.last()); - + if (is_end(begin+1)) + return selection; if (categorize<punctuation_is_word>(*begin) != categorize<punctuation_is_word>(*(begin-1))) --begin; |
