#3922 out_of_range crash in preeditor

master
Andrey Kleshchev 2025-04-16 22:39:02 +03:00 committed by Andrey Kleshchev
parent a99c1e36de
commit 67921fae6d
1 changed files with 18 additions and 3 deletions

View File

@ -2505,9 +2505,24 @@ void LLLineEditor::resetPreedit()
if (hasPreeditString())
{
const S32 preedit_pos = mPreeditPositions.front();
mText.erase(preedit_pos, mPreeditPositions.back() - preedit_pos);
mText.insert(preedit_pos, mPreeditOverwrittenWString);
setCursor(preedit_pos);
const S32 end = mPreeditPositions.back();
const S32 len = end - preedit_pos;
const S32 size = mText.length();
if (preedit_pos < size
&& end <= size
&& preedit_pos >= 0
&& len > 0)
{
mText.erase(preedit_pos, len);
mText.insert(preedit_pos, mPreeditOverwrittenWString);
setCursor(preedit_pos);
}
else
{
LL_WARNS() << "Index out of bounds. Start: " << preedit_pos
<< ", end:" << end
<< ", full string length: " << size << LL_ENDL;
}
mPreeditWString.clear();
mPreeditOverwrittenWString.clear();