selectors.cc: avoid dereferencing buffer end

This commit is contained in:
Maxime Coste 2013-06-04 14:04:52 +02:00
parent 5c2e3b25fa
commit cc70e3ed70

View File

@ -86,11 +86,15 @@ template<bool punctuation_is_word>
Selection select_to_next_word(const Buffer& buffer, const Selection& selection) Selection select_to_next_word(const Buffer& buffer, const Selection& selection)
{ {
Utf8Iterator begin = buffer.iterator_at(selection.last()); Utf8Iterator begin = buffer.iterator_at(selection.last());
if (is_end(begin+1))
return selection;
if (categorize<punctuation_is_word>(*begin) != if (categorize<punctuation_is_word>(*begin) !=
categorize<punctuation_is_word>(*(begin+1))) categorize<punctuation_is_word>(*(begin+1)))
++begin; ++begin;
skip_while(begin, is_eol); skip_while(begin, is_eol);
if (is_end(begin))
return selection;
Utf8Iterator end = begin+1; Utf8Iterator end = begin+1;
if (not punctuation_is_word and is_punctuation(*begin)) 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) Selection select_to_next_word_end(const Buffer& buffer, const Selection& selection)
{ {
Utf8Iterator begin = buffer.iterator_at(selection.last()); Utf8Iterator begin = buffer.iterator_at(selection.last());
if (is_end(begin+1))
return selection;
if (categorize<punctuation_is_word>(*begin) != if (categorize<punctuation_is_word>(*begin) !=
categorize<punctuation_is_word>(*(begin+1))) categorize<punctuation_is_word>(*(begin+1)))
++begin; ++begin;
skip_while(begin, is_eol); skip_while(begin, is_eol);
if (is_end(begin))
return selection;
Utf8Iterator end = begin; Utf8Iterator end = begin;
skip_while(end, is_blank); 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) Selection select_to_previous_word(const Buffer& buffer, const Selection& selection)
{ {
Utf8Iterator begin = buffer.iterator_at(selection.last()); Utf8Iterator begin = buffer.iterator_at(selection.last());
if (is_end(begin+1))
return selection;
if (categorize<punctuation_is_word>(*begin) != if (categorize<punctuation_is_word>(*begin) !=
categorize<punctuation_is_word>(*(begin-1))) categorize<punctuation_is_word>(*(begin-1)))
--begin; --begin;