]> granicus.if.org Git - clang/commitdiff
fix display of source lines with null characters
authorSeth Cantrell <seth.cantrell@gmail.com>
Tue, 17 Apr 2012 20:06:06 +0000 (20:06 +0000)
committerSeth Cantrell <seth.cantrell@gmail.com>
Tue, 17 Apr 2012 20:06:06 +0000 (20:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154947 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnostic.cpp
test/Misc/wnull-character.cpp [new file with mode: 0644]

index 54b2f37e2be9984f0a2b933957e1d999cb12bd44..988baf0995df5bb28b2bcb4608ca4dee0307427d 100644 (file)
@@ -839,10 +839,13 @@ void TextDiagnostic::emitSnippetAndCaret(
 
   // Get information about the buffer it points into.
   bool Invalid = false;
-  const char *BufStart = SM.getBufferData(FID, &Invalid).data();
+  StringRef BufData = SM.getBufferData(FID, &Invalid);
   if (Invalid)
     return;
 
+  const char *BufStart = BufData.data();
+  const char *BufEnd = BufStart + BufData.size();
+
   unsigned LineNo = SM.getLineNumber(FID, FileOffset);
   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
   unsigned CaretEndColNo
@@ -856,7 +859,7 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Compute the line end.  Scan forward from the error position to the end of
   // the line.
   const char *LineEnd = TokPtr;
-  while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
+  while (*LineEnd != '\n' && *LineEnd != '\r' && LineEnd!=BufEnd)
     ++LineEnd;
 
   // FIXME: This shouldn't be necessary, but the CaretEndColNo can extend past
diff --git a/test/Misc/wnull-character.cpp b/test/Misc/wnull-character.cpp
new file mode 100644 (file)
index 0000000..a618da2
Binary files /dev/null and b/test/Misc/wnull-character.cpp differ