summaryrefslogtreecommitdiffstats
path: root/runtime/utf.cc
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-10-30 15:16:16 -0700
committerIan Rogers <irogers@google.com>2014-10-30 15:16:16 -0700
commit8f41dc389bd50b6e31caa3fe9d41cbaf76e4d8d6 (patch)
treee46610c43bb57e78218d7bfd95e486a2165a9c4a /runtime/utf.cc
parenta8825e4b38ae01fa77d255ca423ab2f2b77c6097 (diff)
downloadart-8f41dc389bd50b6e31caa3fe9d41cbaf76e4d8d6.zip
art-8f41dc389bd50b6e31caa3fe9d41cbaf76e4d8d6.tar.gz
art-8f41dc389bd50b6e31caa3fe9d41cbaf76e4d8d6.tar.bz2
Avoid signed arithmetic overflow in UTF hash functions.
Change-Id: I3485ef8445a6034661c1e75dc11ab9ad48884458
Diffstat (limited to 'runtime/utf.cc')
-rw-r--r--runtime/utf.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/runtime/utf.cc b/runtime/utf.cc
index 02cbe3b..735815d 100644
--- a/runtime/utf.cc
+++ b/runtime/utf.cc
@@ -70,27 +70,27 @@ void ConvertUtf16ToModifiedUtf8(char* utf8_out, const uint16_t* utf16_in, size_t
int32_t ComputeUtf16Hash(mirror::CharArray* chars, int32_t offset,
size_t char_count) {
- int32_t hash = 0;
+ uint32_t hash = 0;
for (size_t i = 0; i < char_count; i++) {
hash = hash * 31 + chars->Get(offset + i);
}
- return hash;
+ return static_cast<int32_t>(hash);
}
int32_t ComputeUtf16Hash(const uint16_t* chars, size_t char_count) {
- int32_t hash = 0;
+ uint32_t hash = 0;
while (char_count--) {
hash = hash * 31 + *chars++;
}
- return hash;
+ return static_cast<int32_t>(hash);
}
int32_t ComputeUtf8Hash(const char* chars) {
- int32_t hash = 0;
+ uint32_t hash = 0;
while (*chars != '\0') {
hash = hash * 31 + GetUtf16FromUtf8(&chars);
}
- return hash;
+ return static_cast<int32_t>(hash);
}
int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8_1, const uint16_t* utf8_2) {