]> granicus.if.org Git - clang/commitdiff
In Lexer::getCharAndSizeSlow[NoWarn] make sure we don't go over the end of the buffer
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 Dec 2011 20:19:55 +0000 (20:19 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 Dec 2011 20:19:55 +0000 (20:19 +0000)
when the end of the buffer is immediately after an escaped newline.

Fixes http://llvm.org/PR10153.

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

lib/Lex/Lexer.cpp
test/Lexer/escape_newline.c

index 25e320df51290a98ffc0303941727718b2b2cac4..acb5b8a797edd7fb0dfb1702dce97faef57722ee 100644 (file)
@@ -1171,6 +1171,10 @@ Slash:
       // Found backslash<whitespace><newline>.  Parse the char after it.
       Size += EscapedNewLineSize;
       Ptr  += EscapedNewLineSize;
+
+      if (Ptr[0] == '\0')
+        return '\\';
+
       // Use slow version to accumulate a correct size field.
       return getCharAndSizeSlow(Ptr, Size, Tok);
     }
@@ -1222,6 +1226,9 @@ Slash:
       Size += EscapedNewLineSize;
       Ptr  += EscapedNewLineSize;
 
+      if (Ptr[0] == '\0')
+        return '\\';
+
       // Use slow version to accumulate a correct size field.
       return getCharAndSizeSlowNoWarn(Ptr, Size, Features);
     }
index 43ba41795db83415db12a7f2fbfba55c27d78247..5e3002859c6336a6dce83bfafa63706033f9a3bf 100644 (file)
@@ -1,7 +1,10 @@
 // RUN: %clang_cc1 -E -trigraphs %s | grep -- ' ->'
 // RUN: %clang_cc1 -E -trigraphs %s 2>&1 | grep 'backslash and newline separated by space'
 // RUN: %clang_cc1 -E -trigraphs %s 2>&1 | grep 'trigraph converted'
+// RUN: %clang_cc1 -E -CC -trigraphs %s
 
 // This is an ugly way to spell a -> token.
  -??/      
 >
+
+// \