Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: Commit

system/core


Commit MetaInfo

Revisión9a18eeb02ac0561b7f8b593791392128afddf19e (tree)
Tiempo2014-08-08 23:36:35
AutorChih-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

Cambiar Resumen

Diferencia incremental

--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -134,7 +134,7 @@ size_t strnlen32(const char32_t *s, size_t maxlen)
134134
135135 static inline int32_t utf32_at_internal(const char* cur, size_t *num_read)
136136 {
137- const char first_char = *cur;
137+ const unsigned char first_char = *cur;
138138 if ((first_char & 0x80) == 0) { // ASCII
139139 *num_read = 1;
140140 return *cur;
@@ -365,7 +365,7 @@ ssize_t utf8_length(const char *src)
365365 const char *cur = src;
366366 size_t ret = 0;
367367 while (*cur != '\0') {
368- const char first_char = *cur++;
368+ const unsigned char first_char = *cur++;
369369 if ((first_char & 0x80) == 0) { // ASCII
370370 ret += 1;
371371 continue;
@@ -456,7 +456,7 @@ size_t utf8_to_utf32_length(const char *src, size_t src_len)
456456 for (cur = src, end = src + src_len, num_to_skip = 1;
457457 cur < end;
458458 cur += num_to_skip, ret++) {
459- const char first_char = *cur;
459+ const unsigned char first_char = *cur;
460460 num_to_skip = 1;
461461 if ((first_char & 0x80) == 0) { // ASCII
462462 continue;
Show on old repository browser