From 3172695838372b54c2a488975578eaedaf094e80 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 20 Dec 2022 14:13:36 +0100 Subject: QPdfDocument: make code locale-independent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The C toupper/tolower functions are locale-dependent. Given the right locale (Türkiye, e.g.), tolower(I) is either - ı (LATIN SMALL LETTER DOTLESS I; if representable in current charset) - I (unchanged; if it isn't) Both results are wrong for the present use-case, so use US-ASCII-only QtMiscUtils::toAsciiLower() to side-step the issue. Besides, feeding unfiltered char values into tolower() is UB. You'd first have to cast to uchar: https://en.cppreference.com/w/cpp/string/byte/tolower Task-number: QTBUG-109235 Pick-to: 6.5 6.4 Change-Id: I57887581ba2e548e978223337d681124b30bf754 Reviewed-by: Thiago Macieira --- src/pdf/qpdfdocument.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp index 9b8d20d3b..a3e412c5c 100644 --- a/src/pdf/qpdfdocument.cpp +++ b/src/pdf/qpdfdocument.cpp @@ -17,6 +17,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QRecursiveMutex, pdfMutex) @@ -39,7 +41,7 @@ public: QMetaEnum rolesMetaEnum = doc->metaObject()->enumerator(doc->metaObject()->indexOfEnumerator("PageModelRole")); for (int r = Qt::UserRole; r < int(QPdfDocument::PageModelRole::NRoles); ++r) { auto name = QByteArray(rolesMetaEnum.valueToKey(r)); - name[0] = tolower(name[0]); + name[0] = QtMiscUtils::toAsciiLower(name[0]); m_roleNames.insert(r, name); } connect(doc, &QPdfDocument::statusChanged, this, [this](QPdfDocument::Status s) { -- cgit v1.2.3