aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-30 22:59:50 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-30 22:59:50 +0000
commit33611e0d5ab1372608a7649b1877cd4300621c71 (patch)
tree66558c625d20a78b6aa5bf234da62e88f2f65bf7 /lib/Lex/Lexer.cpp
parent8b9b742ec13a210f5df7d0c9be37f185c1615a41 (diff)
Improve our handling of NULL after an escaping '\' in a string
literal. Fixes <rdar://problem/8044135>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105181 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r--lib/Lex/Lexer.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index cd153e147b..4f2e29e80d 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -753,11 +753,15 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) {
char C = getAndAdvanceChar(CurPtr, Result);
while (C != '"') {
// Skip escaped characters.
+ bool Escaped = false;
if (C == '\\') {
// Skip the escaped character.
C = getAndAdvanceChar(CurPtr, Result);
- } else if (C == '\n' || C == '\r' || // Newline.
- (C == 0 && CurPtr-1 == BufferEnd)) { // End of file.
+ Escaped = true;
+ }
+
+ if ((!Escaped && (C == '\n' || C == '\r')) || // Newline.
+ (C == 0 && CurPtr-1 == BufferEnd)) { // End of file.
if (!isLexingRawMode() && !Features.AsmPreprocessor)
Diag(BufferPtr, diag::err_unterminated_string);
FormTokenWithChars(Result, CurPtr-1, tok::unknown);
@@ -765,6 +769,7 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) {
} else if (C == 0) {
NulCharacter = CurPtr-1;
}
+
C = getAndAdvanceChar(CurPtr, Result);
}