From a30172f8a6264b56eca388e179a74f8fc36ff5da Mon Sep 17 00:00:00 2001 From: souvikdas95 Date: Tue, 17 Jan 2017 20:20:00 +0530 Subject: [PATCH] Fix UTF-8 character parsing due to improper casting (#401) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upcasting of -ve signed characters (char) to signed integers (cell) results in -ve signed integers which don't represent valid printable characters. eg. UTF-8 Character 'δΈ­' (0xE4 0xB8 0xAD) when casted results in 0xFFFFFFE4 0xFFFFFFB8 0xFFFFFFAD which are not valid printable characters. --- amxmodx/string.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amxmodx/string.cpp b/amxmodx/string.cpp index 3b3f4ba4..e4a3b021 100755 --- a/amxmodx/string.cpp +++ b/amxmodx/string.cpp @@ -708,7 +708,7 @@ static cell AMX_NATIVE_CALL parse(AMX *amx, cell *params) /* 3 param */ c = *get_amxaddr(amx, params[iarg++]); while (c-- && *arg) - *cptr++ = (cell)*arg++; + *cptr++ = (unsigned char)*arg++; *cptr = 0; } } @@ -1006,7 +1006,7 @@ static cell AMX_NATIVE_CALL argparse(AMX *amx, cell *params) break; if (size_t(bufpos - buffer) < buflen) - *bufpos++ = input[i]; + *bufpos++ = (unsigned char)input[i]; } *bufpos = '\0'; @@ -1068,7 +1068,7 @@ do_copy: { start = &(string[i]); while (end--) - *right++ = (cell)*start++; + *right++ = (unsigned char)*start++; } *right = '\0'; return 1;