mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher] Fix strlcpy inserted 0 when inserting text
This commit is contained in:
committed by
EmilieNumworks
parent
f054ca6eb1
commit
f2bfc8641f
@@ -99,11 +99,15 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, int locatio
|
||||
for (int k = m_currentDraftTextLength; k >= location && k >= 0; k--) {
|
||||
m_draftTextBuffer[k+textSize] = m_draftTextBuffer[k];
|
||||
}
|
||||
|
||||
// Caution! One char will be overridden by the null-terminating char of strlcpy
|
||||
int overridenCharLocation = location + strlen(text);
|
||||
char overridenChar = m_draftTextBuffer[overridenCharLocation];
|
||||
strlcpy(&m_draftTextBuffer[location], text, m_textBufferSize-location);
|
||||
if (location+textSize > 0) {
|
||||
m_draftTextBuffer[location+textSize-1] = text[textSize-1];
|
||||
}
|
||||
assert(overridenCharLocation < m_textBufferSize);
|
||||
m_draftTextBuffer[overridenCharLocation] = overridenChar;
|
||||
m_currentDraftTextLength += textSize;
|
||||
|
||||
for (size_t i = 0; i < m_currentDraftTextLength; i++) {
|
||||
if (m_draftTextBuffer[i] == '\n') {
|
||||
m_draftTextBuffer[i] = 0;
|
||||
|
||||
Reference in New Issue
Block a user