diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-09-22 06:51:59 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-09-22 06:51:59 +0000 |
commit | 1e39ea08122ef6db924f2ae622e03d4bedde8cd5 (patch) | |
tree | 598267383110c528398d177dec1365ee28ebfc71 /libgo/runtime | |
parent | d47cbb6dd43e5cd02d107f336cbd9554c62acd80 (diff) | |
download | gcc-1e39ea08122ef6db924f2ae622e03d4bedde8cd5.zip gcc-1e39ea08122ef6db924f2ae622e03d4bedde8cd5.tar.gz gcc-1e39ea08122ef6db924f2ae622e03d4bedde8cd5.tar.bz2 |
compiler, runtime: Reject surrogate pair converting int to string.
From-SVN: r191636
Diffstat (limited to 'libgo/runtime')
-rw-r--r-- | libgo/runtime/go-int-to-string.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libgo/runtime/go-int-to-string.c b/libgo/runtime/go-int-to-string.c index e9645bf..17a5fcb 100644 --- a/libgo/runtime/go-int-to-string.c +++ b/libgo/runtime/go-int-to-string.c @@ -17,6 +17,11 @@ __go_int_to_string (int v) unsigned char *retdata; 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) { buf[0] = v; @@ -34,6 +39,10 @@ __go_int_to_string (int v) "replacement character". */ if (v > 0x10ffff) 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) { |