From: Douglas Gregor Date: Fri, 15 May 2009 18:05:24 +0000 (+0000) Subject: When word-wrapping, be more defensive about a ridiculously small number of columns... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c95bd4de800dfc643f0dab0122757f9ca9723fe9;p=clang When word-wrapping, be more defensive about a ridiculously small number of columns. Fixes git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71870 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index f936807b6c..09c29109f1 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -160,10 +160,12 @@ static void SelectInterestingSourceRegion(std::string &SourceLine, // If the end of the interesting region comes before we run out of // space in the terminal, start at the beginning of the line. - if (CaretEnd < Columns - 3) + if (Columns > 3 && CaretEnd < Columns - 3) CaretStart = 0; - unsigned TargetColumns = Columns - 8; // Give us extra room for the ellipses. + unsigned TargetColumns = Columns; + if (TargetColumns > 8) + TargetColumns -= 8; // Give us extra room for the ellipses. unsigned SourceLength = SourceLine.size(); while ((CaretEnd - CaretStart) < TargetColumns) { bool ExpandedRegion = false; diff --git a/test/Misc/message-length.c b/test/Misc/message-length.c index d64b1bfc58..ac5dab99ca 100644 --- a/test/Misc/message-length.c +++ b/test/Misc/message-length.c @@ -4,7 +4,7 @@ // FIXME: This diagnostic is getting truncated very poorly. // RUN: grep -e '^ ...// some long comment text and a brace, eh {} ' %t.msg && // RUN: grep -e '^ \^' %t.msg && - +// RUN: clang -fsyntax-only -fmessage-length=1 %s && // RUN: true // Hack so we can check things better, force the file name and line.