-
Notifications
You must be signed in to change notification settings - Fork 99
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: stardict qstring modification #1708
Conversation
Quality Gate failedFailed conditions |
|
||
return articleText.toStdString(); | ||
auto text = articleText.toUtf8(); | ||
return text.data(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is pretty subtle.
- in the new code,
std::string(toUtf8().data())
will seek for the null byte again - in the old code, toStdString's
std::string(toUtf8().data(),toUtf8().size())
will use the articleText's actual length
Maybe there should be a comment that clarify articleText
may contain null byte, and we want to cut off earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original code is
return (articleText.toUtf8().data());
I changed it into return articleText.toStdString()
,crash still reported on this line.
So I split it into two lines.
I guess articleText.toUtf8()
will generate a temporary string . when chained with .data()
. sometimes the temporary variable has no longer existed. and a crash will throw.
From real environment test ,the crash has more probability to happen when in multithread cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- in the old code, toStdString's
std::string(toUtf8().data(),toUtf8().size())
will use the articleText's actual length
the old code is return (articleText.toUtf8.data());
,toStdString()
is my first attempt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also can not be sure.
But Qt+MSVC +QString are more likely to have issue as the https://bugreports.qt.io/browse/QTBUG-63274 implies
Maybe some link option in CMAKE , /MD /MT etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the correct way to set /MD /MT
set_property(TARGET foo PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
However, CMake's doc says
If the property is not set, then CMake uses the default value MultiThreaded$<$CONFIG:Debug:Debug>DLL to select a MSVC runtime library.
So, I suppose it is set correctly by CMake already.
https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,cmake_minimum_required
will set policy version, and we currently set it aggressively high 😅.
https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#policy-settings
Line 1 in 3ef35da
cmake_minimum_required(VERSION 3.25) # ubuntu 23.04 Fedora 36 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news is that ,with the fix, the crash has gone. really mysterious. |
The changes look fine. For merging this, I don't think we need to know the root cause, which may reveal in the future. Old & new code should be equivalent if things work as they are documented/written anyway 😅. |
the stardict qstring part has caused crash sometimes.
Fix #1702
basic rule: avoid unnecessary conversions between QString and string
Changes:
1.
to
string only.
return (articleText.toUtf8.data());
to
QString stripHtml( const QString & tmp )
to
QString stripHtml( QString tmp )