]> granicus.if.org Git - clang/commitdiff
robustify the conflict marker stuff. Don't add 7 twice, which would
authorChris Lattner <sabre@nondot.org>
Mon, 17 May 2010 20:27:25 +0000 (20:27 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 17 May 2010 20:27:25 +0000 (20:27 +0000)
make it miss (invalid) things like:
<<<<<<<
>>>>>>>

and crash if

<<<<<<<

was at the end of the line.  When we find a >>>>>>> that is not at the
end of the line, make sure to reset Pos so we don't crash on something
like:
<<<<<<< >>>>>>>

This isn't worth making testcases for, since each would require a new file.

rdar://7987078 - signal 11 compiling "<<<<<<<<<<"

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

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

index 83de8c83a95171ca9c1eed15db701ece056f00fc..0925dd73fe931b95b1852c88cb08a3958f7d3d08 100644 (file)
@@ -1422,6 +1422,7 @@ static const char *FindConflictEnd(const char *CurPtr, const char *BufferEnd) {
     if (RestOfBuffer[Pos-1] != '\r' &&
         RestOfBuffer[Pos-1] != '\n') {
       RestOfBuffer = RestOfBuffer.substr(Pos+7);
+      Pos = RestOfBuffer.find(">>>>>>>");
       continue;
     }
     return RestOfBuffer.data()+Pos;
@@ -1451,7 +1452,7 @@ bool Lexer::IsStartOfConflictMarker(const char *CurPtr) {
   
   // Check to see if there is a >>>>>>> somewhere in the buffer at the start of
   // a line to terminate this conflict marker.
-  if (FindConflictEnd(CurPtr+7, BufferEnd)) {
+  if (FindConflictEnd(CurPtr, BufferEnd)) {
     // We found a match.  We are really in a conflict marker.
     // Diagnose this, and ignore to the end of line.
     Diag(CurPtr, diag::err_conflict_marker);
index f86111c3aaa12bd2495fa323a265b6e255ba5d39..45efdec82615a820d22c443d5ea7c2d8bdff48a6 100644 (file)
@@ -4,7 +4,7 @@
 // PR5238
 
 // diff3 style
-<<<<<<< .mine             // expected-error {{version control conflict marker in file}}
+<<<<<<< .mine      // expected-error {{version control conflict marker in file}}
 int x = 4;
 |||||||
 int x = 123;
@@ -13,7 +13,7 @@ float x = 17;
 >>>>>>> .r91107
 
 // normal style.
-<<<<<<< .mine             // expected-error {{version control conflict marker in file}}
+<<<<<<< .mine     // expected-error {{version control conflict marker in file}}
 typedef int y;
 =======
 typedef struct foo *y;
@@ -22,6 +22,7 @@ typedef struct foo *y;
 ;
 y b;
 
+
 int foo() {
   y a = x;
   return x + a;