r224210 - Lex: Don't crash if both conflict markers are on the same line
David Majnemer
david.majnemer at gmail.com
Sat Dec 13 20:53:11 PST 2014
Author: majnemer
Date: Sat Dec 13 22:53:11 2014
New Revision: 224210
URL: http://llvm.org/viewvc/llvm-project?rev=224210&view=rev
Log:
Lex: Don't crash if both conflict markers are on the same line
We would check if the terminator marker is on a newline. However, the
logic would end up out-of-bounds if the terminator marker immediately
follows the start marker.
This fixes PR21820.
Modified:
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/test/Lexer/conflict-marker.c
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=224210&r1=224209&r2=224210&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Sat Dec 13 22:53:11 2014
@@ -2588,8 +2588,8 @@ static const char *FindConflictEnd(const
size_t Pos = RestOfBuffer.find(Terminator);
while (Pos != StringRef::npos) {
// Must occur at start of line.
- if (RestOfBuffer[Pos-1] != '\r' &&
- RestOfBuffer[Pos-1] != '\n') {
+ if (Pos == 0 ||
+ (RestOfBuffer[Pos - 1] != '\r' && RestOfBuffer[Pos - 1] != '\n')) {
RestOfBuffer = RestOfBuffer.substr(Pos+TermLen);
Pos = RestOfBuffer.find(Terminator);
continue;
Modified: cfe/trunk/test/Lexer/conflict-marker.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/conflict-marker.c?rev=224210&r1=224209&r2=224210&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/conflict-marker.c (original)
+++ cfe/trunk/test/Lexer/conflict-marker.c Sat Dec 13 22:53:11 2014
@@ -36,3 +36,5 @@ int foo() {
y a = x;
return x + a - z;
}
+
+<<<<<<<>>>>>>> // expected-error {{expected identifier}}
More information about the cfe-commits
mailing list