summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-22 06:51:59 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-22 06:51:59 +0000
commit2c7db76690518189d65db150f51560f64447e3eb (patch)
tree598267383110c528398d177dec1365ee28ebfc71 /libgo
parenta7bb36919c22adcda5cc76df8117847c6a194477 (diff)
downloadgcc-2c7db76690518189d65db150f51560f64447e3eb.tar.gz
compiler, runtime: Reject surrogate pair converting int to string.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191636 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r--libgo/runtime/go-int-to-string.c9
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 e9645bf98fe..17a5fcb04c0 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)
{