From f10ec682adc2b80dea82298b5e3f1f6b28f7b9cf Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Fri, 10 Apr 2020 16:57:53 +0200 Subject: [PATCH] Fix index out of range bug --- src/util/tagged_string.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/tagged_string.cpp b/src/util/tagged_string.cpp index 3303314e..66f35530 100644 --- a/src/util/tagged_string.cpp +++ b/src/util/tagged_string.cpp @@ -338,11 +338,12 @@ void cursor_to_index_range(const String& str, size_t cursor, size_t& start, size size_t cursor_to_index(const String& str, size_t cursor, Movement dir) { size_t start, end; cursor_to_index_range(str, cursor, start, end); + assert(end <= str.size()+1); if (dir == MOVE_MID) { // find the middle between start and end // if the string in between contains a pair "" or "" returns the middle // otherwise returns start - for (size_t i = start ; i < end ; ) { + for (size_t i = start ; i < end && i < str.size() ; ) { if (str.GetChar(i) == _('<')) { String tag1 = tag_at(str, i); i = skip_tag(str, i);