QStringAlgorithms::simplified_helper: add missing check for detached
Otherwise, we modify shared strings that happened to be rvalues. Task-number: QTBUG-44706 Change-Id: Ia0aac2f09e9245339951ffff13c85bfc912f03d1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>bb10
parent
a8c74ddcf7
commit
53ce0d1a31
|
|
@ -114,7 +114,7 @@ template <typename StringType> struct QStringAlgorithms
|
|||
return str;
|
||||
const Char *src = str.cbegin();
|
||||
const Char *end = str.cend();
|
||||
NakedStringType result = isConst ?
|
||||
NakedStringType result = isConst || !str.isDetached() ?
|
||||
StringType(str.size(), Qt::Uninitialized) :
|
||||
qMove(str);
|
||||
|
||||
|
|
|
|||
|
|
@ -2040,6 +2040,9 @@ void tst_QString::simplified()
|
|||
QFETCH(QString, full);
|
||||
QFETCH(QString, simple);
|
||||
|
||||
QString orig_full = full;
|
||||
orig_full.data(); // forces a detach
|
||||
|
||||
QString result = full.simplified();
|
||||
if (simple.isNull()) {
|
||||
QVERIFY2(result.isNull(), qPrintable("'" + full + "' did not yield null: " + result));
|
||||
|
|
@ -2048,6 +2051,12 @@ void tst_QString::simplified()
|
|||
} else {
|
||||
QCOMPARE(result, simple);
|
||||
}
|
||||
QCOMPARE(full, orig_full);
|
||||
|
||||
// without detaching:
|
||||
QString copy1 = full;
|
||||
QCOMPARE(qMove(full).simplified(), simple);
|
||||
QCOMPARE(full, orig_full);
|
||||
|
||||
// force a detach
|
||||
if (!full.isEmpty())
|
||||
|
|
|
|||
Loading…
Reference in New Issue