summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-10-20 13:24:58 -0700
committerAlex Ray <aray@google.com>2013-07-30 13:56:55 -0700
commit2881c85e38c662050e9635c6ff3861a3be09674f (patch)
treef534d7fb16a40c077e943391f40ca322e0fa87c2
parent935d1bba3bf92992fba9a8322fe7ca7a5fbffb39 (diff)
downloadsystem_core-2881c85e38c662050e9635c6ff3861a3be09674f.zip
system_core-2881c85e38c662050e9635c6ff3861a3be09674f.tar.gz
system_core-2881c85e38c662050e9635c6ff3861a3be09674f.tar.bz2
Add length-equality test in String operator== checks.
Change-Id: I6ebc6ef85aac4539269f137c1f29f95b9828d4f9
-rw-r--r--include/utils/String16.h4
-rw-r--r--include/utils/String8.h4
2 files changed, 6 insertions, 2 deletions
diff --git a/include/utils/String16.h b/include/utils/String16.h
index 07a0c11..d98b2d0 100644
--- a/include/utils/String16.h
+++ b/include/utils/String16.h
@@ -205,7 +205,9 @@ inline bool String16::operator<=(const String16& other) const
inline bool String16::operator==(const String16& other) const
{
- return strzcmp16(mString, size(), other.mString, other.size()) == 0;
+ const size_t n1 = size();
+ const size_t n2 = other.size();
+ return n1 == n2 && strzcmp16(mString, n1, other.mString, n2) == 0;
}
inline bool String16::operator!=(const String16& other) const
diff --git a/include/utils/String8.h b/include/utils/String8.h
index cef8eca..a129222 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -418,7 +418,9 @@ inline bool String8::operator<=(const String8& other) const
inline bool String8::operator==(const String8& other) const
{
- return strcmp(mString, other.mString) == 0;
+ return (SharedBuffer::sizeFromData(mString) ==
+ SharedBuffer::sizeFromData(other.mString)) &&
+ strcmp(mString, other.mString) == 0;
}
inline bool String8::operator!=(const String8& other) const