From: Richard Smith Date: Wed, 13 Jun 2012 05:41:29 +0000 (+0000) Subject: Fix off-by-one error in UTF-16 encoding: don't try to use a surrogate pair for U... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59b26d84b64510158e23d80eba077b844b7e0b04;p=clang Fix off-by-one error in UTF-16 encoding: don't try to use a surrogate pair for U+FFFF. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158391 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 2930d6a5ff..9b0bc70345 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -322,7 +322,7 @@ static void EncodeUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, // using reinterpret_cast. UTF16 *ResultPtr = reinterpret_cast(ResultBuf); - if (UcnVal < (UTF32)0xFFFF) { + if (UcnVal <= (UTF32)0xFFFF) { *ResultPtr = UcnVal; ResultBuf += 2; return; diff --git a/test/Lexer/char-literal.cpp b/test/Lexer/char-literal.cpp index 5dc53608f8..8556d468cb 100644 --- a/test/Lexer/char-literal.cpp +++ b/test/Lexer/char-literal.cpp @@ -22,3 +22,6 @@ char m = '👿'; // expected-error {{character too large for enclosing character char32_t n = U'ab'; // expected-error {{Unicode character literals may not contain multiple characters}} char16_t o = '👽'; // expected-error {{character too large for enclosing character literal type}} + +char16_t p[2] = u"\U0000FFFF"; +char16_t q[2] = u"\U00010000"; // expected-error {{too long}}