From f1e86bdcc55adbd5bc7af04ccf64af01674ea64c Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 19 Aug 2011 16:43:30 +0000 Subject: [PATCH] fix counting of UTF8-charwidth - Ctdl_GetUtf8SequenceLength(): testbyte needs to be unsigned char, else >> will shift us new bits in from the left - we need to shift 'test' to the right - start counting at 0 --- libcitadel/lib/stringbuf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 3a9ccf58e..55daf6192 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -3312,14 +3312,16 @@ void StrBuf_RFC822_2_Utf8(StrBuf *Target, */ static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE) { - int n = 1; - char test = (1<<7); + int n = 0; + unsigned char test = (1<<7); if ((*CharS & 0xC0) == 0) return 1; - while ((n < 8) && ((test & *CharS) != 0)) { - test = test << 1; + while ((n < 8) && + ((test & ((unsigned char)*CharS)) != 0)) + { + test = test >> 1; n ++; } if ((n > 6) || ((CharE - CharS) < n)) -- 2.30.2