Convert Latin1 to UTF-16 before passing to ICU API

The ICU UChar type is a UTF-16 type, not a single-byte type, so
passing it the data() of a QByteArray representing an ID is misguided.

Fixes: QTBUG-97486
Pick-to: 6.2 6.2.1
Change-Id: I6789f491674b1d913eb8655d788b497e2fc06f7a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-10-13 18:26:43 +02:00
parent dbc434dc09
commit f83a3c4b6e

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2013 John Layt <jlayt@kde.org> ** Copyright (C) 2013 John Layt <jlayt@kde.org>
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -264,11 +265,10 @@ static QList<QByteArray> uenumToIdList(UEnumeration *uenum)
static int ucalDaylightOffset(const QByteArray &id) static int ucalDaylightOffset(const QByteArray &id)
{ {
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
const int32_t dstMSecs = ucal_getDSTSavings(reinterpret_cast<const UChar *>(id.data()), &status); const QString utf16 = QString::fromLatin1(id);
if (U_SUCCESS(status)) const int32_t dstMSecs = ucal_getDSTSavings(
return (dstMSecs / 1000); reinterpret_cast<const UChar *>(utf16.data()), &status);
else return U_SUCCESS(status) ? dstMSecs / 1000 : 0;
return 0;
} }
// Create the system default time zone // Create the system default time zone