Skip to content

Commit 7d40bef

Browse files
committed
Fix yet another mishap
1 parent c47ddb1 commit 7d40bef

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang/lib/Frontend/TextDiagnostic.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,16 @@ static void selectInterestingSourceRegion(
517517
// highlighting information. In particular, if we've removed
518518
// from the front of the line, we need to move the style ranges to the
519519
// left and remove unneeded ranges.
520+
// Note in particular that variables like CaretEnd are defined in the
521+
// CaretLine, which only contains ASCII, while the style ranges are defined in
522+
// the source line, where we have to care for the byte-index != column-index
523+
// case.
520524
Bytes BytesRemoved =
521525
FrontColumnsRemoved > FrontEllipse.size()
522526
? (Map.columnToByte(FrontColumnsRemoved) - Bytes(FrontEllipse.size()))
523527
: 0;
524-
Bytes CodeEnd = Map.columnToByte(CaretEnd);
528+
Bytes CodeEnd =
529+
CaretEnd < Map.columns() ? Map.columnToByte(CaretEnd.V) : CaretEnd.V;
525530
for (TextDiagnostic::StyleRange &R : Styles) {
526531
if (R.End < static_cast<unsigned>(BytesRemoved.V)) {
527532
R.Start = R.End = std::numeric_limits<int>::max();
@@ -535,7 +540,7 @@ static void selectInterestingSourceRegion(
535540
// Don't leak into the ellipse at the end.
536541
if (R.Start < static_cast<unsigned>(CodeEnd.V) &&
537542
R.End > static_cast<unsigned>(CodeEnd.V))
538-
R.End = CodeEnd.V;
543+
R.End = CodeEnd.V + 1; // R.End is inclusive.
539544

540545
// Remove style ranges after the end of the snippet.
541546
if (R.Start >= static_cast<unsigned>(CodeEnd.V))

0 commit comments

Comments
 (0)