Tweak CXLoadedDiagnosticSetImpl::makeString() to include an extra null character, and change the creation of the FixIT's string to again just rely on this string (instead of duplicating it when calling createCXString).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144389 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp
index 607f3bb..510f617 100644
--- a/tools/libclang/CXLoadedDiagnostic.cpp
+++ b/tools/libclang/CXLoadedDiagnostic.cpp
@@ -55,8 +55,11 @@
 
 llvm::StringRef CXLoadedDiagnosticSetImpl::makeString(const char *blob,
                                                       unsigned bloblen) {
-  char *mem = Alloc.Allocate<char>(bloblen);
+  char *mem = Alloc.Allocate<char>(bloblen + 1);
   memcpy(mem, blob, bloblen);
+  // Add a null terminator for those clients accessing the buffer
+  // like a c-string.
+  mem[bloblen] = '\0';
   return llvm::StringRef(mem, bloblen);
 }
 
@@ -100,7 +103,7 @@
 }
 
 CXString CXLoadedDiagnostic::getSpelling() const {
-  return cxstring::createCXString(Spelling, false);  
+  return cxstring::createCXString(Spelling, false);
 }
 
 CXString CXLoadedDiagnostic::getDiagnosticOption(CXString *Disable) const {
@@ -242,7 +245,7 @@
       if (errorString)
         *errorString = createCXString("");
     }
-  
+
   CXDiagnosticSet load(const char *file);
 };
 }
@@ -626,8 +629,8 @@
         llvm::StringRef RetStr;
         if (readString(TopDiags, RetStr, "FIXIT", Record, BlobStart, BlobLen))
           return Failure;
-        D->FixIts.push_back(std::make_pair(SR, createCXString(RetStr)));
-        continue;        
+        D->FixIts.push_back(std::make_pair(SR, createCXString(RetStr, false)));
+        continue;
       }
         
       case serialized_diags::RECORD_DIAG: {