Fix string compression for embedded zero chars.
Treat embedded zero character as non-ASCII.
Test: m test-art-host
Test: m test-art-host with string compression enabled.
Bug: 31040547
Change-Id: Iea6e92f89d424953814953ba27f1c7a991589c65
diff --git a/runtime/mirror/string-inl.h b/runtime/mirror/string-inl.h
index 6870fda..95516ac 100644
--- a/runtime/mirror/string-inl.h
+++ b/runtime/mirror/string-inl.h
@@ -305,8 +305,11 @@
template<typename MemoryType>
bool String::AllASCII(const MemoryType* const chars, const int length) {
+ static_assert(std::is_unsigned<MemoryType>::value, "Expecting unsigned MemoryType");
for (int i = 0; i < length; ++i) {
- if (chars[i] >= 0x80) {
+ // Valid ASCII characters are in range 1..0x7f. Zero is not considered ASCII
+ // because it would complicate the detection of ASCII strings in Modified-UTF8.
+ if ((chars[i] - 1u) >= 0x7fu) {
return false;
}
}