From: Wilfried Goesgens Date: Fri, 19 Aug 2011 16:43:30 +0000 (+0000) Subject: fix counting of UTF8-charwidth X-Git-Tag: v7.87~4 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=25440cd0453f1995d6a240c2160143c105737a8a 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 --- diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index ed2eb0094..86ce299d9 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -3181,14 +3181,16 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* */ 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))