From 6345c0f60f37f598a40536578938a6cd623b6e7f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Oct 2020 16:01:55 +0200 Subject: Fix UTF-16 encoding/decoding of high code points Everything outside of BMP was handled incorrectly and was coded as completely different code points. --- common/rfb/util.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index 00e2831c..85b668fc 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -315,8 +315,9 @@ namespace rfb { *dst++ = L'\0'; return 1; } else if (src < 0x110000) { - *dst++ = 0xd800 | ((src >> 10) & 0x07ff); - *dst++ = 0xdc00 | (src & 0x07ff); + src -= 0x10000; + *dst++ = 0xd800 | ((src >> 10) & 0x03ff); + *dst++ = 0xdc00 | (src & 0x03ff); *dst++ = L'\0'; return 2; } else { @@ -358,7 +359,7 @@ namespace rfb { return 1; } - *dst = 0x10000 | ((*dst & 0x03ff) << 10); + *dst = 0x10000 + ((*dst & 0x03ff) << 10); *dst |= *src & 0x3ff; return 2; -- cgit v1.2.3