Skip to content

Commit ca2ea73

Browse files
committed
[Clang] Fix an out of bound access in -verify comment parsing
When the comment ends with a splice at EOF. Fixes #141221
1 parent 2a8495c commit ca2ea73

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ bool VerifyDiagnosticConsumer::HandleComment(Preprocessor &PP,
812812
C2 += C.substr(last, loc-last);
813813
last = loc + 1;
814814

815-
if (C[last] == '\n' || C[last] == '\r') {
815+
if (last < C.size() && (C[last] == '\n' || C[last] == '\r')) {
816816
++last;
817817

818818
// Escape \r\n or \n\r, but not \n\n.

clang/test/Frontend/verify-gh141221.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -verify %s
2+
3+
// Check that we don't crash if the file ends in a splice
4+
// This file should *NOT* end with a new line
5+
a;
6+
// expected-error@-1 {{}} \

0 commit comments

Comments
 (0)