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:
parent
ef666fa83d
commit
66fb075ad0
@ -292,7 +292,7 @@ bool SkString::equals(const char text[]) const {
|
|||||||
bool SkString::equals(const char text[], size_t len) const {
|
bool SkString::equals(const char text[], size_t len) const {
|
||||||
SkASSERT(len == 0 || text != nullptr);
|
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) {
|
SkString& SkString::operator=(const SkString& src) {
|
||||||
|
Loading…
Reference in New Issue
Block a user