[apps/eschr] Don't copy an expr when editing it, if it is too long

Scenario: Create a new sequence which is the multiplication of a lot of
imaginary i. Save it (many multiplication sign are added), then try to
edit it again, in linear edition mode: the text overflows the buffer. If
we still copied it, it might get copied until the middle of a code point,
which would make the UTF8Decoder crash afterwards.
This commit is contained in:
Léa Saviot
2020-02-13 15:12:11 +01:00
committed by EmilieNumworks
parent 176d55b7fa
commit 9544f1c961
2 changed files with 11 additions and 1 deletions

View File

@@ -33,7 +33,11 @@ void ExpressionModel::text(const Storage::Record * record, char * buffer, size_t
if (symbol != 0) {
e = e.replaceSymbolWithExpression(Symbol::Builder(UCodePointUnknown), Symbol::Builder(symbol));
}
e.serialize(buffer, bufferSize);
int serializedSize = e.serialize(buffer, bufferSize);
if (serializedSize >= bufferSize - 1) {
// It is very likely that the buffer is overflowed
buffer[0] = 0;
}
}
bool ExpressionModel::isCircularlyDefined(const Storage::Record * record, Poincare::Context * context) const {