summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Drougge <bearded@longhaired.org>2022-02-23 16:23:22 +0200
committerAlexander Naumov <alexander_naumov@opensuse.org>2022-02-23 16:23:22 +0200
commit916d0523137b6ce9d56c2ec6a602a3dc471779a4 (patch)
tree499523fe32788389476dce4e1c96a4b5d211c1f5
parent1bfe555cd334feccdf55a0fd2891f743b2ffc7a0 (diff)
downloadscreen-916d0523137b6ce9d56c2ec6a602a3dc471779a4.tar.gz
[PATCH] encoding: Replace out of range unicode with U+FFFD
Also correct the mask for four byte UTF-8. bug #62097
-rw-r--r--src/encoding.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/encoding.c b/src/encoding.c
index 9cebddd..976978a 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -675,14 +675,14 @@ int c;
AddUtf8(combchars[c - 0xd800]->c1);
c = combchars[c - 0xd800]->c2;
}
+
+ /* replace out of range values with U+FFFD "replacement character" */
+ if (c < 0 || c > 0x10ffff)
+ c = 0xfffd;
+
if (c >= 0x10000)
{
- if (c >= 0x200000)
- {
- AddChar((c & 0x3000000) >> 12 ^ 0xf8);
- c = (c & 0xffffff) ^ ((0xf0 ^ 0x80) << 18);
- }
- AddChar((c & 0x1fc0000) >> 18 ^ 0xf0);
+ AddChar((c & 0x1c0000) >> 18 ^ 0xf0);
c = (c & 0x3ffff) ^ ((0xe0 ^ 0x80) << 12);
}
if (c >= 0x800)
@@ -719,17 +719,14 @@ char *p;
int c;
{
int l = 1;
+ /* replace out of range values with U+FFFD "replacement character" */
+ if (c < 0 || c > 0x10ffff)
+ c = 0xfffd;
+
if (c >= 0x10000)
{
- if (c >= 0x200000)
- {
- if (p)
- *p++ = (c & 0x3000000) >> 12 ^ 0xf8;
- l++;
- c = (c & 0xffffff) ^ ((0xf0 ^ 0x80) << 18);
- }
if (p)
- *p++ = (c & 0x1fc0000) >> 18 ^ 0xf0;
+ *p++ = (c & 0x1c0000) >> 18 ^ 0xf0;
l++;
c = (c & 0x3ffff) ^ ((0xe0 ^ 0x80) << 12);
}