From 70712b276e40bbe11e5063dfc7e82ce3209929cd Mon Sep 17 00:00:00 2001 From: Seth Cantrell Date: Tue, 17 Apr 2012 20:06:06 +0000 Subject: [PATCH] fix display of source lines with null characters git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154947 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/TextDiagnostic.cpp | 7 +++++-- test/Misc/wnull-character.cpp | Bin 0 -> 143 bytes 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test/Misc/wnull-character.cpp diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index 54b2f37e2b..988baf0995 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 diff --git a/test/Misc/wnull-character.cpp b/test/Misc/wnull-character.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a618da272a13f98e9ebb3100bed68e19daab51cb GIT binary patch literal 143 zcmWm6K?{N~7>DuB`xJi!I}~Ht(aeh!LD3e4b4HNqC>2v<^D1}>n&5@GR z{@D;^kdHWe)?e9sH$vY1$2m!z4w~2mq!HV4nc;_{b*AbJy&xk8ODu=ZvWag^W@17q jRHs9A&T&a}QLi^sWt)g$o;3{WePpZ#>}RlOlb!ej-GwXN literal 0 HcmV?d00001 -- 2.40.0