From 052986a46bd5d14db5aba5376884c694273f0bf0 Mon Sep 17 00:00:00 2001 From: herlesupreeth Date: Mon, 25 Dec 2023 11:11:56 +0100 Subject: [PATCH] smsops: fix utf8 to ucs2 conversion --- src/modules/smsops/smsops_impl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/smsops/smsops_impl.c b/src/modules/smsops/smsops_impl.c index 703092542b0..9ed55328d8e 100644 --- a/src/modules/smsops/smsops_impl.c +++ b/src/modules/smsops/smsops_impl.c @@ -606,17 +606,17 @@ int utf8_to_ucs2(char *utf8, int utf8_len, char *ucs2, int buffer_len) } else if((utf8_char & 0xF0) == 0xE0) { // Three-byte UTF-8 character codepoint = ((utf8_char & 0x0F) << 12) - | (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 6) - | ((unsigned char)utf8[utf8_index + 2] & 0x3F); + | (((unsigned char)utf8[utf8_index] & 0x3F) << 6) + | ((unsigned char)utf8[utf8_index + 1] & 0x3F); utf8_index += 2; tmp_buff[ucs2_index++] = (uint8_t)(codepoint >> 8); tmp_buff[ucs2_index++] = (uint8_t)(codepoint & 0xFF); } else if((utf8_char & 0xF8) == 0xF0) { // Four-byte UTF-8 character codepoint = ((utf8_char & 0x07) << 18) - | (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 12) - | (((unsigned char)utf8[utf8_index + 2] & 0x3F) << 6) - | ((unsigned char)utf8[utf8_index + 3] & 0x3F); + | (((unsigned char)utf8[utf8_index] & 0x3F) << 12) + | (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 6) + | ((unsigned char)utf8[utf8_index + 2] & 0x3F); utf8_index += 3; // Convert to UCS-2 surrogate pair codepoint -= 0x10000;