diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/runtime/rune.c | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/runtime/rune.c')
-rw-r--r-- | src/pkg/runtime/rune.c | 9 |
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 |