[perl #22946] Bug in Unicode surrogate pair conversion in Perl_utf16_to_utf8
Dinger, Tom [Mon, 14 Jul 2003 05:35:15 +0000 (05:35 +0000)]
From: "Dinger, Tom" (via RT) <perlbug-followup@perl.org>
Message-ID: <rt-22946-60715.1.00007189884266@rt.perl.org>

p4raw-id: //depot/perl@20211

utf8.c

diff --git a/utf8.c b/utf8.c
index e86b3fd..21d0f08 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -831,7 +831,8 @@ Perl_utf16_to_utf8(pTHX_ U8* p, U8* d, I32 bytelen, I32 *newlen)
            continue;
        }
        if (uv >= 0xd800 && uv < 0xdbff) {      /* surrogates */
-           UV low = *p++;
+           UV low = (p[0] << 8) + p[1];
+           p += 2;
            if (low < 0xdc00 || low >= 0xdfff)
                Perl_croak(aTHX_ "Malformed UTF-16 surrogate");
            uv = ((uv - 0xd800) << 10) + (low - 0xdc00) + 0x10000;