Fix array index out of bounds
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>
Wed, 27 Jan 2016 07:33:50 +0000 (07:33 +0000)
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>
Wed, 27 Jan 2016 07:33:50 +0000 (07:33 +0000)
Differential Revision: http://reviews.llvm.org/D16582

llvm-svn: 258911

clang/lib/Driver/MSVCToolChain.cpp

index 1d2d20b..0834be7 100644 (file)
@@ -141,8 +141,8 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName,
       nextKey++;
     size_t partialKeyLength = keyEnd - keyPath;
     char partialKey[256];
-    if (partialKeyLength > sizeof(partialKey))
-      partialKeyLength = sizeof(partialKey);
+    if (partialKeyLength >= sizeof(partialKey))
+      partialKeyLength = sizeof(partialKey) - 1;
     strncpy(partialKey, keyPath, partialKeyLength);
     partialKey[partialKeyLength] = '\0';
     HKEY hTopKey = NULL;