From eede42808452f645b1d7b11ac42f170715a4cfdb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 22 May 2023 11:47:03 +0200 Subject: [PATCH] Fix crash on QLocale::monthName().simplified() Because monthName() returns a fromRawData() view of internal locale data, we have to avoid simplified()'s optimisation of re-using an unshared object; even if it's not shared, it's not mutable. Fixes: QTBUG-113415 Change-Id: Idac93175434c7a8a21228605578adbe4cc918e7a Reviewed-by: Fabian Kosmale Reviewed-by: Marc Mutz Reviewed-by: Qt CI Bot --- src/corelib/text/qstring.cpp | 2 ++ tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 2d2d351f090..9e6868cf02f 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -5737,6 +5737,8 @@ QString QString::simplified_helper(const QString &str) QString QString::simplified_helper(QString &str) { + if (IS_RAW_DATA(str.d)) // Force a copy, even if not shared: + return QStringAlgorithms::simplified_helper(str); return QStringAlgorithms::simplified_helper(str); } diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 6bd9e5c25a5..2816ba3bd3d 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -2547,6 +2547,7 @@ void tst_QLocale::monthName() QCOMPARE(c.monthName(1, QLocale::LongFormat), QLatin1String("January")); QCOMPARE(c.monthName(1, QLocale::ShortFormat), QLatin1String("Jan")); QCOMPARE(c.monthName(1, QLocale::NarrowFormat), QLatin1String("1")); + QCOMPARE(c.monthName(3).simplified(), "March"); // QTBUG-113415 (crash) const QLocale de("de_DE"); QCOMPARE(de.monthName(12, QLocale::LongFormat), QLatin1String("Dezember"));