• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

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

system/corennnnn


Commit MetaInfo

Révisionfacd201bd2867cc98c96277d1c264290dadfa278 (tree)
l'heure2015-12-22 12:23:00
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

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

Modification

--- 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;
@@ -366,7 +366,7 @@ ssize_t utf8_length(const char *src)
366366 const char *cur = src;
367367 size_t ret = 0;
368368 while (*cur != '\0') {
369- const char first_char = *cur++;
369+ const unsigned char first_char = *cur++;
370370 if ((first_char & 0x80) == 0) { // ASCII
371371 ret += 1;
372372 continue;
@@ -457,7 +457,7 @@ size_t utf8_to_utf32_length(const char *src, size_t src_len)
457457 for (cur = src, end = src + src_len, num_to_skip = 1;
458458 cur < end;
459459 cur += num_to_skip, ret++) {
460- const char first_char = *cur;
460+ const unsigned char first_char = *cur;
461461 num_to_skip = 1;
462462 if ((first_char & 0x80) == 0) { // ASCII
463463 continue;