diff options
author | Seth Cantrell <seth.cantrell@gmail.com> | 2012-04-18 02:44:48 +0000 |
---|---|---|
committer | Seth Cantrell <seth.cantrell@gmail.com> | 2012-04-18 02:44:48 +0000 |
commit | 3acf764931e0f3e3ce75db0f4c4d400ee588d6b0 (patch) | |
tree | d256563c221b983f699e9dc2fc92a51b65302320 /lib/Frontend/TextDiagnostic.cpp | |
parent | 6749dd50869281f9b49ad5960e25288c15a71cac (diff) |
fix display of source lines with null characters
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154981 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnostic.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnostic.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index 3c35ab24f2..66362381df 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -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 |