mirror of git://gcc.gnu.org/git/gcc.git
compiler, runtime: Reject surrogate pair converting int to string.
From-SVN: r191636
This commit is contained in:
parent
d47cbb6dd4
commit
1e39ea0812
|
|
@ -1312,6 +1312,12 @@ Lex::append_char(unsigned int v, bool is_character, std::string* str,
|
||||||
// Turn it into the "replacement character".
|
// Turn it into the "replacement character".
|
||||||
v = 0xfffd;
|
v = 0xfffd;
|
||||||
}
|
}
|
||||||
|
if (v >= 0xd800 && v < 0xe000)
|
||||||
|
{
|
||||||
|
warning_at(location, 0,
|
||||||
|
"unicode code point 0x%x is invalid surrogate pair", v);
|
||||||
|
v = 0xfffd;
|
||||||
|
}
|
||||||
if (v <= 0xffff)
|
if (v <= 0xffff)
|
||||||
{
|
{
|
||||||
buf[0] = 0xe0 + (v >> 12);
|
buf[0] = 0xe0 + (v >> 12);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ __go_int_to_string (int v)
|
||||||
unsigned char *retdata;
|
unsigned char *retdata;
|
||||||
struct __go_string ret;
|
struct __go_string ret;
|
||||||
|
|
||||||
|
/* A negative value is not valid UTF-8; turn it into the replacement
|
||||||
|
character. */
|
||||||
|
if (v < 0)
|
||||||
|
v = 0xfffd;
|
||||||
|
|
||||||
if (v <= 0x7f)
|
if (v <= 0x7f)
|
||||||
{
|
{
|
||||||
buf[0] = v;
|
buf[0] = v;
|
||||||
|
|
@ -34,6 +39,10 @@ __go_int_to_string (int v)
|
||||||
"replacement character". */
|
"replacement character". */
|
||||||
if (v > 0x10ffff)
|
if (v > 0x10ffff)
|
||||||
v = 0xfffd;
|
v = 0xfffd;
|
||||||
|
/* If the value is a surrogate pair, which is invalid in UTF-8,
|
||||||
|
turn it into the replacement character. */
|
||||||
|
if (v >= 0xd800 && v < 0xe000)
|
||||||
|
v = 0xfffd;
|
||||||
|
|
||||||
if (v <= 0xffff)
|
if (v <= 0xffff)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue