[escher/text_field] Fix insertion size computation

This commit is contained in:
Léa Saviot
2020-03-27 11:18:55 +01:00
committed by Émilie Feral
parent ac3a09bdeb
commit fd1b0e08ee

View File

@@ -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;