aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-14 09:22:40 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-14 09:22:40 -0800
commitd4897591fddf8f2a4860066449fb7dd8b0cc7b77 (patch)
treeda215b78e52e601ee48d296b639a3c224c9234e7
parent36e6e266b882b7687fb526dc13eeb23ffbc2b85e (diff)
Don't pass null to memcmp.
This will allow us to add nonnull-attribute to the UBSAN bot. We are in fact hitting a case where one of the arguments is null and the other not, which seems dicey. I think the scenario is comparing the empty pathref with another path ref that's just been COWed, without any verbs or points yet. BUG=skia: Review URL: https://codereview.chromium.org/732643002
-rw-r--r--src/core/SkPathRef.cpp6
-rw-r--r--tests/PathTest.cpp6
2 files changed, 11 insertions, 1 deletions
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index dffb6a3646..ad85fd06a8 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -193,12 +193,18 @@ bool SkPathRef::operator== (const SkPathRef& ref) const {
SkASSERT(!genIDMatch);
return false;
}
+ if (0 == ref.fVerbCnt) {
+ SkASSERT(0 == ref.fPointCnt);
+ return true;
+ }
+ SkASSERT(this->verbsMemBegin() && ref.verbsMemBegin());
if (0 != memcmp(this->verbsMemBegin(),
ref.verbsMemBegin(),
ref.fVerbCnt * sizeof(uint8_t))) {
SkASSERT(!genIDMatch);
return false;
}
+ SkASSERT(this->points() && ref.points());
if (0 != memcmp(this->points(),
ref.points(),
ref.fPointCnt * sizeof(SkPoint))) {
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index bc3a3d7bdb..94b91d261b 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -3435,7 +3435,11 @@ static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool
path.dump(&wStream, force, dumpAsHex);
SkAutoDataUnref data(wStream.copyToData());
REPORTER_ASSERT(reporter, data->size() == strlen(str));
- REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
+ if (strlen(str) > 0) {
+ REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
+ } else {
+ REPORTER_ASSERT(reporter, data->data() == NULL || !memcmp(data->data(), str, strlen(str)));
+ }
}
static void test_dump(skiatest::Reporter* reporter) {