From 34fc647ccd10ddf2933e084a0af59c7d0814e71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 25 Jan 2019 08:44:54 +0100 Subject: [PATCH] [escher/text_field] Code cleaning --- escher/src/text_field.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 3e795925d..d88407ee1 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -105,12 +105,12 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, const char memmove(const_cast(location + textSize), location, (m_draftTextBuffer + m_currentDraftTextLength + 1) - location); - // Caution! One char will be overridden by the null-terminating char of strlcpy - char * overridenCharLocation = const_cast(location + strlen(text)); - char overridenChar = *overridenCharLocation; + // Caution! One byte will be overridden by the null-terminating char of strlcpy + char * overridenByteLocation = const_cast(location + strlen(text)); + char overridenByte = *overridenByteLocation; strlcpy(const_cast(location), text, (m_draftTextBuffer + m_textBufferSize) - location); - assert(overridenCharLocation < m_draftTextBuffer + m_textBufferSize); - *overridenCharLocation = overridenChar; + assert(overridenByteLocation < m_draftTextBuffer + m_textBufferSize); + *overridenByteLocation = overridenByte; m_currentDraftTextLength += textSize; UTF8Decoder decoder(m_draftTextBuffer); @@ -120,6 +120,7 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, const char while (codePoint != UCodePointNull) { assert(codePointPointer < m_draftTextBuffer + m_textBufferSize); if (codePoint == '\n') { + assert(UTF8Decoder::CharSizeOfCodePoint('\n') == 1); *(const_cast(codePointPointer)) = 0; m_currentDraftTextLength = codePointPointer - m_draftTextBuffer; break;