diff options
Diffstat (limited to 'lib/Frontend/TextDiagnostic.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnostic.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index f7c0d60ae4..c2562eb5fc 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -1096,18 +1096,26 @@ void TextDiagnostic::emitSnippetAndCaret( unsigned LineNo = SM.getLineNumber(FID, FileOffset); unsigned ColNo = SM.getColumnNumber(FID, FileOffset); + + // Arbitrarily stop showing snippets when the line is too long. + static const unsigned MaxLineLength = 4096; + if (ColNo > MaxLineLength) + return; // Rewind from the current position to the start of the line. const char *TokPtr = BufStart+FileOffset; const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based. - // 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') ++LineEnd; + // Arbitrarily stop showing snippets when the line is too long. + if (LineEnd - LineStart > MaxLineLength) + return; + // Copy the line of code into an std::string for ease of manipulation. std::string SourceLine(LineStart, LineEnd); |