From eaa78fb2b1ca98d4fed13060b1e6324d6197e461 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 8 Jul 2024 18:34:23 +0200 Subject: [PATCH] Fix sameLocale() assertions in qlocale.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assertion is about entries at the same index having matching language, script and territory tags. I forgot that the system locale has its m_index set to match the closest-matching CLDR data table, so might not have the same tags as the locale_data[] entry at its given index. Fixes: QTBUG-126390 Change-Id: Icb8cc09cc2a9d66a0af301a300f44923d7400ce9 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 1df1c0b6fdc40a3cb9e89c4d07adc89c37c7582b) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 86ab072b736..25461601fa1 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3021,6 +3021,9 @@ QString QLocale::standaloneDayName(int day, FormatType type) const // Only used in assertions [[maybe_unused]] static bool sameLocale(const QLocaleData *locale, const QCalendarLocale &calendar) { + // NB: pass locale_data[] entry at the same index as the calendar one; this + // shall usually be the locale's m_data, but for the system locale it's + // different. return locale->m_language_id == calendar.m_language_id && locale->m_script_id == calendar.m_script_id && locale->m_territory_id == calendar.m_territory_id; @@ -3135,7 +3138,7 @@ QString QCalendarBackend::monthName(const QLocale &locale, int month, int, { Q_ASSERT(month >= 1 && month <= maximumMonthsInYear()); const QCalendarLocale &monthly = localeMonthIndexData()[locale.d->m_index]; - Q_ASSERT(sameLocale(locale.d->m_data, monthly)); + Q_ASSERT(sameLocale(&locale_data[locale.d->m_index], monthly)); return rawMonthName(monthly, localeMonthData(), month, format); } @@ -3171,7 +3174,7 @@ QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, { Q_ASSERT(month >= 1 && month <= maximumMonthsInYear()); const QCalendarLocale &monthly = localeMonthIndexData()[locale.d->m_index]; - Q_ASSERT(sameLocale(locale.d->m_data, monthly)); + Q_ASSERT(sameLocale(&locale_data[locale.d->m_index], monthly)); return rawStandaloneMonthName(monthly, localeMonthData(), month, format); }