summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-10 10:12:29 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-11 07:19:00 +0200
commitdee140a79a3c87184abbe7d7edac4533b137ca16 (patch)
tree755195b90f0f4f7f44aab84f3d17751380f16e2b
parent60f83a76756342de66d0d97353e8392083deae3a (diff)
Windows: Fix registry string read failures
On Windows 7, it has been observed that the time zone registry key is a string of size 256 padded with 0. Use QString::fromWCharArray(), relying on 0-termination to cope with it. Pick-to: 5.15 Fixes: QTBUG-84455 Change-Id: I5d242e2de73c1ea09344aee8de8eea941bc52bab Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/corelib/kernel/qwinregistry.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/corelib/kernel/qwinregistry.cpp b/src/corelib/kernel/qwinregistry.cpp
index 6566dd3c76..ac3b2ec370 100644
--- a/src/corelib/kernel/qwinregistry.cpp
+++ b/src/corelib/kernel/qwinregistry.cpp
@@ -86,17 +86,15 @@ QString QWinRegistryKey::stringValue(QStringView subKey) const
|| (type != REG_SZ && type != REG_EXPAND_SZ) || size <= 2) {
return result;
}
- // Reserve more for rare cases where trailing '\0' are missing in registry,
- // otherwise chop off the '\0' received.
- QString buffer(int(size / sizeof(wchar_t)), Qt::Uninitialized);
- if (RegQueryValueEx(m_key, subKeyC, nullptr, &type,
- reinterpret_cast<LPBYTE>(buffer.data()), &size) == ERROR_SUCCESS) {
- if (buffer.endsWith(QChar::Null))
- buffer.chop(1);
- } else {
- buffer.clear();
- }
- return buffer;
+ // Reserve more for rare cases where trailing '\0' are missing in registry.
+ // Rely on 0-termination since strings of size 256 padded with 0 have been
+ // observed (QTBUG-84455).
+ size += 2;
+ QVarLengthArray<unsigned char> buffer(static_cast<int>(size));
+ std::fill(buffer.data(), buffer.data() + size, 0u);
+ if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, buffer.data(), &size) == ERROR_SUCCESS)
+ result = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(buffer.constData()));
+ return result;
}
QPair<DWORD, bool> QWinRegistryKey::dwordValue(QStringView subKey) const