OSDN Git Service

libutils: fix incorrect calculation in utf8_length() method
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 8 Aug 2014 10:17:04 +0000 (18:17 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sat, 6 May 2017 14:52:19 +0000 (22:52 +0800)
commit55a0da0cc9e88028ca78804564cd5e8acea9fa9c
tree13c971c709990f34391fd01740ced64dd45b6c8b
parent9e89fe3e1816e8e7a5142780bf12302ee64d1b7e
libutils: fix incorrect calculation in utf8_length() method

The first character of utf-8 could be larger than 128. If use signed char
variable to hold it, it would be treated as negative. That may result in
some unexpected errors.

For example, without this patch, suppose the code is 0xE88888, then
first_char is 0xE8 and converted to int32_t type (0xFFFFFFE8) and
masked with (~to_ignore_mask). The result utf32 is FFF08208
which is incorrect.

Change-Id: I72b355f380865bc375251eb287fc225fd585a115
libutils/Unicode.cpp