From cc70e3ed708e231e581dfba94ada9fe7d7cad89c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 4 Jun 2013 14:04:52 +0200 Subject: [PATCH] selectors.cc: avoid dereferencing buffer end --- src/selectors.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 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(*begin) != categorize(*(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 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(*begin) != categorize(*(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 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(*begin) != categorize(*(begin-1))) --begin;