diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-12-20 14:13:36 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-23 20:01:56 +0000 |
commit | cc8607c4422cf987083b5462e1194b3b1216d8c7 (patch) | |
tree | e94f1e2a585ffc595070afb12748d2e5822be58d | |
parent | baeefb0922497b77baf99509d0d5f4ff68860a6f (diff) |
QPdfDocument: make code locale-independent
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
Change-Id: I57887581ba2e548e978223337d681124b30bf754
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 3172695838372b54c2a488975578eaedaf094e80)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/pdf/qpdfdocument.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
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 <QMutex> #include <QVector2D> +#include <QtCore/private/qtools_p.h> + 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) { |