Fix UB in SkString::equal(nullptr) when empty.

It is undefined behavior to memcmp with a nullptr. It is possible to
get into such a state if the SkString is itself empty and compared
against nullptr using SkString::equal.

Change-Id: I7a55d7beb5ed454c73a56f47c3729f3790a5fd78
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306951
Auto-Submit: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Ben Wagner 2020-07-30 18:54:27 -04:00 committed by Skia Commit-Bot
parent ef666fa83d
commit 66fb075ad0

View File

@ -292,7 +292,7 @@ bool SkString::equals(const char text[]) const {
bool SkString::equals(const char text[], size_t len) const {
SkASSERT(len == 0 || text != nullptr);
return fRec->fLength == len && !memcmp(fRec->data(), text, len);
return fRec->fLength == len && !sk_careful_memcmp(fRec->data(), text, len);
}
SkString& SkString::operator=(const SkString& src) {