summaryrefslogtreecommitdiffstats
path: root/libdexfile/dex/utf.cc
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2018-12-10 12:14:36 +0000
committerVladimir Marko <vmarko@google.com>2018-12-10 15:14:40 +0000
commitca0f2dceb2ab4fdbebf9d2b75c774c363b4191b4 (patch)
treea2d6822b068e29c2bab2edc643dd208206e2e77b /libdexfile/dex/utf.cc
parentb023b3fd99a3369479e965c8e5d1d79b2491f75d (diff)
downloadart-ca0f2dceb2ab4fdbebf9d2b75c774c363b4191b4.tar.gz
art-ca0f2dceb2ab4fdbebf9d2b75c774c363b4191b4.tar.bz2
art-ca0f2dceb2ab4fdbebf9d2b75c774c363b4191b4.zip
Fix ComputeModifiedUtf8Hash().
Explicitly cast the character to uint8_t so that we do not produce different results depending on whether the platform has a signed or unsigned char. Test: Additional test in utf_test. Bug: 120749178 Change-Id: Icf329baa9eb95c2db820b51873e72d95aabf398e
Diffstat (limited to 'libdexfile/dex/utf.cc')
-rw-r--r--libdexfile/dex/utf.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/libdexfile/dex/utf.cc b/libdexfile/dex/utf.cc
index d09da735f2..ed07568fbc 100644
--- a/libdexfile/dex/utf.cc
+++ b/libdexfile/dex/utf.cc
@@ -194,9 +194,10 @@ int32_t ComputeUtf16HashFromModifiedUtf8(const char* utf8, size_t utf16_length)
uint32_t ComputeModifiedUtf8Hash(const char* chars) {
uint32_t hash = 0;
while (*chars != '\0') {
- hash = hash * 31 + *chars++;
+ hash = hash * 31 + static_cast<uint8_t>(*chars);
+ ++chars;
}
- return static_cast<int32_t>(hash);
+ return hash;
}
int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8, const uint16_t* utf16,