[cfe-commits] r144389 - /cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp

Ted Kremenek kremenek at apple.com
Fri Nov 11 07:19:48 PST 2011


Author: kremenek
Date: Fri Nov 11 09:19:48 2011
New Revision: 144389

URL: http://llvm.org/viewvc/llvm-project?rev=144389&view=rev
Log:
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).

Modified:
    cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp

Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=144389&r1=144388&r2=144389&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Fri Nov 11 09:19:48 2011
@@ -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: {





More information about the cfe-commits mailing list