]> granicus.if.org Git - clang/commitdiff
Locate VS InstallDir in the presence of newer runtime
authorHans Wennborg <hans@hanshq.net>
Thu, 10 Oct 2013 18:03:08 +0000 (18:03 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 10 Oct 2013 18:03:08 +0000 (18:03 +0000)
This fixes getSystemRegistryString() in WindowsToolChain.cpp to
make sure that the VS version that it picks has an InstallDir.
Previously we would look for the highest version os VS and check
for InstallDir afterwards.

Patch by Yaron Keren!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192374 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/WindowsToolChain.cpp

index ad84d02f5981f712463422c267c6a3792996db9b..db36f1eba713e6d6d15036a80087f0b4de94ae26 100644 (file)
@@ -146,30 +146,29 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName,
         char numBuf[32];
         strncpy(numBuf, sp, sizeof(numBuf) - 1);
         numBuf[sizeof(numBuf) - 1] = '\0';
-        double value = strtod(numBuf, NULL);
-        if (value > bestValue) {
-          bestIndex = (int)index;
-          bestValue = value;
+        double dvalue = strtod(numBuf, NULL);
+        if (dvalue > bestValue) {
+          // Test that InstallDir is indeed there before keeping this index.
+          // Open the chosen key path remainder.
           strcpy(bestName, keyName);
+          // Append rest of key.
+          strncat(bestName, nextKey, sizeof(bestName) - 1);
+          bestName[sizeof(bestName) - 1] = '\0';
+          lResult = RegOpenKeyEx(hTopKey, bestName, 0,
+                                 KEY_READ | KEY_WOW64_32KEY, &hKey);
+          if (lResult == ERROR_SUCCESS) {
+            lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
+              (LPBYTE)value, &valueSize);
+            if (lResult == ERROR_SUCCESS) {
+              bestIndex = (int)index;
+              bestValue = dvalue;
+              returnValue = true;
+            }
+            RegCloseKey(hKey);
+          }
         }
         size = sizeof(keyName) - 1;
       }
-      // If we found the highest versioned key, open the key and get the value.
-      if (bestIndex != -1) {
-        // Append rest of key.
-        strncat(bestName, nextKey, sizeof(bestName) - 1);
-        bestName[sizeof(bestName) - 1] = '\0';
-        // Open the chosen key path remainder.
-        lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ | KEY_WOW64_32KEY,
-                               &hKey);
-        if (lResult == ERROR_SUCCESS) {
-          lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
-            (LPBYTE)value, &valueSize);
-          if (lResult == ERROR_SUCCESS)
-            returnValue = true;
-          RegCloseKey(hKey);
-        }
-      }
       RegCloseKey(hTopKey);
     }
   } else {