From c9feec7cd7b1812994c5cc46da10fd02aeee77e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 29 Jan 2019 11:31:09 +0100 Subject: [PATCH] [unicode] Fix stop condition in TextArea::Text::removeRemainingLine --- escher/src/text_area.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 7c54eb401..2a96c85c8 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -224,7 +224,7 @@ size_t TextArea::Text::removeRemainingLine(const char * location, int direction) } while (nextCodePoint != '\n' && ((direction > 0 && nextCodePoint != 0) - || (direction < 0 && codePointPosition >= m_buffer))) + || (direction < 0 && codePointPosition > m_buffer))) { if (direction > 0) { codePointPosition = decoder.stringPosition(); @@ -234,14 +234,15 @@ size_t TextArea::Text::removeRemainingLine(const char * location, int direction) codePointPosition = decoder.stringPosition(); } } - size_t delta = direction > 0 ? codePointPosition - location : location - codePointPosition; - if (delta == 0) { - return 0; - } char * dst = const_cast(direction > 0 ? location : codePointPosition); char * src = const_cast(direction > 0 ? codePointPosition : location); - assert(src > dst); + assert(src >= dst); + + size_t delta = src - dst; + if (delta == 0) { + return 0; + } for (size_t index = src - m_buffer; index < m_bufferSize; index++) { *dst = *src; if (*src == 0) {