summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/rune.c
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-03-04 21:27:43 +0100
committerMichael Stapelberg <michael@stapelberg.de>2013-03-04 21:27:43 +0100
commitad47422646a18ffcb47cec916ef7393c923f2e76 (patch)
tree7c7861fb3d9539d61c1dcfd5b8dadee974c25760 /src/pkg/runtime/rune.c
parent2c8d5d584a79781ca41bb6f4b396893fbbac5b97 (diff)
parent04b08da9af0c450d645ab7389d1467308cfc2db8 (diff)
downloadgolang-ad47422646a18ffcb47cec916ef7393c923f2e76.tar.gz
Merge tag 'upstream/1.1_hg20130304' into debian-sid
Upstream version 1.1~hg20130304
Diffstat (limited to 'src/pkg/runtime/rune.c')
-rw-r--r--src/pkg/runtime/rune.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/pkg/runtime/rune.c b/src/pkg/runtime/rune.c
index 86ee76ddd..ed867269d 100644
--- a/src/pkg/runtime/rune.c
+++ b/src/pkg/runtime/rune.c
@@ -47,6 +47,9 @@ enum
Runeerror = 0xFFFD,
Runeself = 0x80,
+ SurrogateMin = 0xD800,
+ SurrogateMax = 0xDFFF,
+
Bad = Runeerror,
Runemax = 0x10FFFF, /* maximum rune value */
@@ -128,6 +131,8 @@ runtime·charntorune(int32 *rune, uint8 *str, int32 length)
l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
if(l <= Rune2)
goto bad;
+ if (SurrogateMin <= l && l <= SurrogateMax)
+ goto bad;
*rune = l;
return 3;
}
@@ -193,13 +198,15 @@ runtime·runetochar(byte *str, int32 rune) /* note: in original, arg2 was point
}
/*
- * If the Rune is out of range, convert it to the error rune.
+ * If the Rune is out of range or a surrogate half, convert it to the error rune.
* Do this test here because the error rune encodes to three bytes.
* Doing it earlier would duplicate work, since an out of range
* Rune wouldn't have fit in one or two bytes.
*/
if (c > Runemax)
c = Runeerror;
+ if (SurrogateMin <= c && c <= SurrogateMax)
+ c = Runeerror;
/*
* three character sequence