From: Argyrios Kyrtzidis Date: Wed, 21 Dec 2011 20:19:55 +0000 (+0000) Subject: In Lexer::getCharAndSizeSlow[NoWarn] make sure we don't go over the end of the buffer X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f132dcaae82ebfc44c4fe0e84bf0b1f95e9d1251;p=clang In Lexer::getCharAndSizeSlow[NoWarn] make sure we don't go over the end of the buffer 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 --- diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 25e320df51..acb5b8a797 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1171,6 +1171,10 @@ Slash: // Found backslash. 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); } diff --git a/test/Lexer/escape_newline.c b/test/Lexer/escape_newline.c index 43ba41795d..5e3002859c 100644 --- a/test/Lexer/escape_newline.c +++ b/test/Lexer/escape_newline.c @@ -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. -??/ > + +// \