- Do not read past the end of the utf32_array.

Review URL: https://codereview.chromium.org//11447009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15847 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
iposva@google.com 2012-12-07 17:18:22 +00:00
parent 2d5c3b2101
commit 19a89a947e
2 changed files with 24 additions and 6 deletions

View file

@ -10011,16 +10011,17 @@ bool String::Equals(const uint16_t* utf16_array, intptr_t len) const {
bool String::Equals(const int32_t* utf32_array, intptr_t len) const {
CodePointIterator it(*this);
intptr_t i = 0;
while (it.Next()) {
if (it.Current() != static_cast<int32_t>(utf32_array[i])) {
bool has_more = it.Next();
while (has_more && (i < len)) {
if ((it.Current() != static_cast<int32_t>(utf32_array[i]))) {
return false;
}
// Advance both streams forward.
++i;
has_more = it.Next();
}
if (i != len) {
return false;
}
return true;
// Strings are only true iff we reached the end in both streams.
return (i == len) && !has_more;
}

View file

@ -1448,6 +1448,23 @@ TEST_CASE(StringEqualsUtf8) {
}
TEST_CASE(StringEqualsUTF32) {
const String& empty = String::Handle(String::New(""));
const String& t_str = String::Handle(String::New("t"));
const String& th_str = String::Handle(String::New("th"));
const int32_t chars[] = {'t', 'h', 'i', 's'};
EXPECT(!empty.Equals(chars, -1));
EXPECT(empty.Equals(chars, 0));
EXPECT(!empty.Equals(chars, 1));
EXPECT(!t_str.Equals(chars, 0));
EXPECT(t_str.Equals(chars, 1));
EXPECT(!t_str.Equals(chars, 2));
EXPECT(!th_str.Equals(chars, 1));
EXPECT(th_str.Equals(chars, 2));
EXPECT(!th_str.Equals(chars, 3));
}
TEST_CASE(ExternalOneByteString) {
uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
intptr_t len = ARRAY_SIZE(characters);