• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂2a8b2915430bbf7c983040a13cd37e81c57c7bf8 (tree)
時間2016-08-18 17:03:58
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

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

Change Summary

差異

--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -129,7 +129,7 @@ size_t strnlen32(const char32_t *s, size_t maxlen)
129129
130130 static inline int32_t utf32_at_internal(const char* cur, size_t *num_read)
131131 {
132- const char first_char = *cur;
132+ const unsigned char first_char = *cur;
133133 if ((first_char & 0x80) == 0) { // ASCII
134134 *num_read = 1;
135135 return *cur;
@@ -391,7 +391,7 @@ ssize_t utf8_length(const char *src)
391391 const char *cur = src;
392392 size_t ret = 0;
393393 while (*cur != '\0') {
394- const char first_char = *cur++;
394+ const unsigned char first_char = *cur++;
395395 if ((first_char & 0x80) == 0) { // ASCII
396396 ret += 1;
397397 continue;
@@ -482,7 +482,7 @@ size_t utf8_to_utf32_length(const char *src, size_t src_len)
482482 for (cur = src, end = src + src_len, num_to_skip = 1;
483483 cur < end;
484484 cur += num_to_skip, ret++) {
485- const char first_char = *cur;
485+ const unsigned char first_char = *cur;
486486 num_to_skip = 1;
487487 if ((first_char & 0x80) == 0) { // ASCII
488488 continue;