diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-30 22:59:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-30 22:59:50 +0000 |
commit | fe4a4107d80dfc0f42eddce4e62cdd888ccba5cb (patch) | |
tree | 3ba9b90603fedc9760386e21a20041701fc32d5b /clang/lib | |
parent | 50d612d6c677a42075249b40f09db4efcfa21bf5 (diff) | |
download | bcm5719-llvm-fe4a4107d80dfc0f42eddce4e62cdd888ccba5cb.tar.gz bcm5719-llvm-fe4a4107d80dfc0f42eddce4e62cdd888ccba5cb.zip |
Improve our handling of NULL after an escaping '\' in a string
literal. Fixes <rdar://problem/8044135>.
llvm-svn: 105181
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index cd153e147b5..4f2e29e80d4 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/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); } |