mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[code] Console: when displaying results, do not split in lines in middle
of code points. Otherwise, this triggers crashes when manipulaping the text (removing code point for instance)
This commit is contained in:
@@ -424,11 +424,24 @@ void ConsoleController::appendTextToOutputAccumulationBuffer(const char * text,
|
||||
memcpy(&m_outputAccumulationBuffer[endOfAccumulatedText], text, length);
|
||||
return;
|
||||
}
|
||||
memcpy(&m_outputAccumulationBuffer[endOfAccumulatedText], text, spaceLeft-1);
|
||||
/* The text to append is too long for the buffer. We need to split it in
|
||||
* chunks. We take special care not to break in the middle of code points! */
|
||||
int maxAppendedTextLength = spaceLeft-1; // we keep the last char to null-terminate the buffer
|
||||
int appendedTextLength = 0;
|
||||
UTF8Decoder decoder(text);
|
||||
while (decoder.stringPosition() - text <= maxAppendedTextLength) {
|
||||
appendedTextLength = decoder.stringPosition() - text;
|
||||
decoder.nextCodePoint();
|
||||
}
|
||||
memcpy(&m_outputAccumulationBuffer[endOfAccumulatedText], text, appendedTextLength);
|
||||
// The last char of m_outputAccumulationBuffer is kept to 0 to ensure a null-terminated text.
|
||||
assert(endOfAccumulatedText+appendedTextLength < k_outputAccumulationBufferSize);
|
||||
m_outputAccumulationBuffer[endOfAccumulatedText+appendedTextLength] = 0;
|
||||
flushOutputAccumulationBufferToStore();
|
||||
appendTextToOutputAccumulationBuffer(&text[spaceLeft-1], length - (spaceLeft - 1));
|
||||
appendTextToOutputAccumulationBuffer(&text[appendedTextLength], length - appendedTextLength);
|
||||
}
|
||||
|
||||
// TODO: is it really needed? Maybe discard to optimize?
|
||||
void ConsoleController::emptyOutputAccumulationBuffer() {
|
||||
for (int i = 0; i < k_outputAccumulationBufferSize; i++) {
|
||||
m_outputAccumulationBuffer[i] = 0;
|
||||
|
||||
Reference in New Issue
Block a user