summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-rune.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-rune.c')
-rw-r--r--libgo/runtime/go-rune.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c
index 7e31eb8d622..acdecb02467 100644
--- a/libgo/runtime/go-rune.c
+++ b/libgo/runtime/go-rune.c
@@ -53,6 +53,14 @@ __go_get_rune (const unsigned char *str, size_t len, int *rune)
*rune = (((c & 0xf) << 12)
+ ((c1 & 0x3f) << 6)
+ (c2 & 0x3f));
+
+ if (*rune >= 0xd800 && *rune < 0xe000)
+ {
+ /* Invalid surrogate half; return replace character. */
+ *rune = 0xfffd;
+ return 1;
+ }
+
return 3;
}