diff options
author | bsalomon <bsalomon@google.com> | 2015-06-04 15:34:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-04 15:34:34 -0700 |
commit | 89d59883f39d4097183e632b86da439052499527 (patch) | |
tree | 7c73ebc641417a93262a9ab2717132ce513bb716 | |
parent | af6005c8a20cea18d515f55b9f5bb1ee8e8b6833 (diff) |
Remove memcmp from GrProgramDesc op== and Less
Works around an ASAN complaint.
BUG=skia:3891
Review URL: https://codereview.chromium.org/1154773007
-rw-r--r-- | src/gpu/GrProgramDesc.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h index b306f02e4f..05b52cc7cd 100644 --- a/src/gpu/GrProgramDesc.h +++ b/src/gpu/GrProgramDesc.h @@ -39,9 +39,17 @@ public: return *this; } - bool operator== (const GrProgramDesc& other) const { - // The length is masked as a hint to the compiler that the address will be 4 byte aligned. - return 0 == memcmp(this->asKey(), other.asKey(), this->keyLength() & ~0x3); + bool operator== (const GrProgramDesc& that) const { + SkASSERT(SkIsAlign4(this->keyLength())); + int l = this->keyLength() >> 2; + const uint32_t* aKey = this->asKey(); + const uint32_t* bKey = that.asKey(); + for (int i = 0; i < l; ++i) { + if (aKey[i] != bKey[i]) { + return false; + } + } + return true; } bool operator!= (const GrProgramDesc& other) const { @@ -49,7 +57,16 @@ public: } static bool Less(const GrProgramDesc& a, const GrProgramDesc& b) { - return memcmp(a.asKey(), b.asKey(), a.keyLength() & ~0x3) < 0; + SkASSERT(SkIsAlign4(a.keyLength())); + int l = a.keyLength() >> 2; + const uint32_t* aKey = a.asKey(); + const uint32_t* bKey = b.asKey(); + for (int i = 0; i < l; ++i) { + if (aKey[i] != bKey[i]) { + return aKey[i] < bKey[i] ? true : false; + } + } + return false; } struct KeyHeader { |