]> granicus.if.org Git - clang/commitdiff
Lex: Don't crash if both conflict markers are on the same line
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 14 Dec 2014 04:53:11 +0000 (04:53 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 14 Dec 2014 04:53:11 +0000 (04:53 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224210 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Lexer/conflict-marker.c

index c2e9716123c4d53cb019a75ac8c5992e23d38d7f..ca5252e1c9ce62de0a726f25811c0c1eb638c419 100644 (file)
@@ -2588,8 +2588,8 @@ static const char *FindConflictEnd(const char *CurPtr, const char *BufferEnd,
   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;
index e5bc7f33e45f94ed62ddbd1e2dc493e68dc58fd3..2611827d2ace0725b57bb7d70d85c91f3d5f991a 100644 (file)
@@ -36,3 +36,5 @@ int foo() {
   y a = x;
   return x + a - z;
 }
+
+<<<<<<<>>>>>>> // expected-error {{expected identifier}}