r277005 - [Driver] Fix Windows SDK Detection

Zachary Turner via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 28 10:13:32 PDT 2016


Author: zturner
Date: Thu Jul 28 12:13:32 2016
New Revision: 277005

URL: http://llvm.org/viewvc/llvm-project?rev=277005&view=rev
Log:
[Driver] Fix Windows SDK Detection

This fixes a couple of bugs in Windows SDK Detection.

1. `readFullStringValue` returns a bool, but was being compared
   with ERROR_SUCCESS.
2. `RegQueryValueExW` might return the null terminator in the
   queried value which will result in incorrect values being
   returned from `getSystemRegistryString`.

Patch By: comicfans44 at gmail.com
Reviewed By: zturner
Differential Revision: http://reviews.llvm.org/D21946

Modified:
    cfe/trunk/lib/Driver/MSVCToolChain.cpp

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=277005&r1=277004&r2=277005&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Thu Jul 28 12:13:32 2016
@@ -114,6 +114,9 @@ static bool readFullStringValue(HKEY hke
   if (result == ERROR_SUCCESS) {
     std::wstring WideValue(reinterpret_cast<const wchar_t *>(buffer.data()),
                            valueSize / sizeof(wchar_t));
+    if (valueSize && WideValue.back() == L'\0') {
+        WideValue.pop_back();
+    }
     // The destination buffer must be empty as an invariant of the conversion
     // function; but this function is sometimes called in a loop that passes in
     // the same buffer, however. Simply clear it out so we can overwrite it.
@@ -191,8 +194,7 @@ static bool getSystemRegistryString(cons
           lResult = RegOpenKeyExA(hTopKey, bestName.c_str(), 0,
                                   KEY_READ | KEY_WOW64_32KEY, &hKey);
           if (lResult == ERROR_SUCCESS) {
-            lResult = readFullStringValue(hKey, valueName, value);
-            if (lResult == ERROR_SUCCESS) {
+            if (readFullStringValue(hKey, valueName, value)) {
               bestValue = dvalue;
               if (phValue)
                 *phValue = bestName;
@@ -209,8 +211,7 @@ static bool getSystemRegistryString(cons
     lResult =
         RegOpenKeyExA(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
     if (lResult == ERROR_SUCCESS) {
-      lResult = readFullStringValue(hKey, valueName, value);
-      if (lResult == ERROR_SUCCESS)
+      if (readFullStringValue(hKey, valueName, value))
         returnValue = true;
       if (phValue)
         phValue->clear();




More information about the cfe-commits mailing list