Skip to content
Permalink
Browse files

Merge PR #2470: OSInfo: fix new Windows 10 OSInfo to not include NUL …

…values in the displayable version string.
  • Loading branch information...
mkrautz committed Aug 6, 2016
2 parents ab58864 + 2df5f2f commit 0a9c69db1ae3178ac540a89aacafce8323ff279e
Showing with 17 additions and 3 deletions.
  1. +17 −3 src/OSInfo.cpp
@@ -23,6 +23,20 @@
#include "Version.h"

#if defined(Q_OS_WIN)
// regString converts a wchar_t string of size to a
// QString. If the string contains a NUL value, that
// NUL value will terminate the string.
static QString regString(wchar_t *string, int size) {
if (size <= 0) {
return QString();
}
// If string contains a NUL, adjust the size such
// that the NUL is not included in the returned
// string.
const size_t adjustedSize = wcsnlen(string, static_cast<size_t>(size));
return QString::fromWCharArray(string, adjustedSize);
}

/// Query for a Windows 10-style displayable version.
///
/// This returns a string of the kind:
@@ -67,23 +81,23 @@ static QString win10DisplayableVersion() {
RegCloseKey(key);
return QString();
}
productName = QString::fromWCharArray(buf, static_cast<int>(len / sizeof(buf[0])));
productName = regString(buf, static_cast<int>(len / sizeof(buf[0])));

len = sizeof(buf);
err = RegQueryValueEx(key, L"ReleaseId", NULL, NULL, reinterpret_cast<LPBYTE>(&buf[0]), &len);
if (err != ERROR_SUCCESS) {
RegCloseKey(key);
return QString();
}
releaseId = QString::fromWCharArray(buf, static_cast<int>(len / sizeof(buf[0])));
releaseId = regString(buf, static_cast<int>(len / sizeof(buf[0])));

len = sizeof(buf);
err = RegQueryValueEx(key, L"CurrentBuild", NULL, NULL, reinterpret_cast<LPBYTE>(&buf[0]), &len);
if (err != ERROR_SUCCESS) {
RegCloseKey(key);
return QString();
}
currentBuild = QString::fromWCharArray(buf, static_cast<int>(len / sizeof(buf[0])));
currentBuild = regString(buf, static_cast<int>(len / sizeof(buf[0])));

len = sizeof(dw);
err = RegQueryValueEx(key, L"UBR", NULL, NULL, reinterpret_cast<LPBYTE>(&dw), &len);

0 comments on commit 0a9c69d

Please sign in to comment.
You can’t perform that action at this time.