Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when characters over 2^30 #313

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/editor/editwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,17 @@ void EditWrapper::customEvent(QEvent *e)
QByteArray text = parseEvent->m_contentData.mid(parseEvent->m_alreadyReadOffset, needReadLen);
QTextCodec::ConverterState state;
QString data = parseEvent->m_codec->toUnicode(text.constData(), text.size(), &state);
parseEvent->m_cursor.insertText(data);

// TODO: Qt5 just under 2^30 characters in one QString.
// In Qt6.8, the value up to almost 2^63, release on Qt6.
try {
parseEvent->m_cursor.insertText(data);
} catch (std::exception &e) {
qCritical() << "Insert file data error" << e.what();
// read abort!
m_bAsyncReadFileFinished = true;
return;
}

// 当前为首次读取
if (0 == parseEvent->m_alreadyReadOffset) {
Expand Down
Loading