From fd1b0e08eeadd5033dad6bf2be7f70ba570ca775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 27 Mar 2020 11:18:55 +0100 Subject: [PATCH] [escher/text_field] Fix insertion size computation --- escher/src/text_field.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index ebd9bd48a..aa1d128b7 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -130,8 +130,8 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, char * loca memmove(location + textLength, location, (s_draftTextBuffer + m_currentDraftTextLength + 1) - location); // Caution! One byte will be overridden by the null-terminating char of strlcpy - size_t copySize = std::min(textLength, (s_draftTextBuffer + m_draftTextBufferSize) - location); - char * overridenByteLocation = location + copySize; + size_t copySize = std::min(textLength + 1, (s_draftTextBuffer + m_draftTextBufferSize) - location); + char * overridenByteLocation = location + copySize - 1; char overridenByte = *overridenByteLocation; strlcpy(location, text, copySize); *overridenByteLocation = overridenByte;