aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-07-09 09:54:10 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-09 09:54:11 -0700
commit1c577cd3ee331944b9061ee0eec147b211ee563c (patch)
treeca4e2ea83c7b2343844c4e60d5d7c03353178d30 /src/effects
parent2e09d18f78f5772d2d9506ff8024ca8542654358 (diff)
Always initialize SkDashPathEffect fields.
SkDashPathEffect is flattened into a hash key as part of the old-and-busted SkPicture paint deduping code. If all its fields aren't intialized, this hash will be based on uninitialized data. This means the hash won't be deterministic, and worse, Valgrind and MSAN will make us feel bad. An alternative to this is to have SkDashPath::CalcDashParameters always guarantee it writes something to all its output parameters, even when the dash intervals make no sense. I like it being dumb and its users defensive, but could go either way. BUG=391001 R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/379813004
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkDashPathEffect.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 2838b1ff3e..d91e7be977 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -11,8 +11,11 @@
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
-SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
- SkScalar phase) {
+SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase)
+ : fPhase(0)
+ , fInitialDashLength(0)
+ , fInitialDashIndex(0)
+ , fIntervalLength(0) {
SkASSERT(intervals);
SkASSERT(count > 1 && SkAlign2(count) == count);
@@ -24,8 +27,8 @@ SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count,
}
// set the internal data members
- SkDashPath::CalcDashParameters(phase, fIntervals, fCount, &fInitialDashLength,
- &fInitialDashIndex, &fIntervalLength, &fPhase);
+ SkDashPath::CalcDashParameters(phase, fIntervals, fCount,
+ &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase);
}
SkDashPathEffect::~SkDashPathEffect() {
@@ -249,7 +252,12 @@ SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) {
return SkNEW_ARGS(SkDashPathEffect, (buffer));
}
-SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
+SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer)
+ : INHERITED(buffer)
+ , fPhase(0)
+ , fInitialDashLength(0)
+ , fInitialDashIndex(0)
+ , fIntervalLength(0) {
bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_Version);
if (useOldPic) {
fInitialDashIndex = buffer.readInt();
@@ -280,7 +288,7 @@ SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
} else {
// set the internal data members, fPhase should have been between 0 and intervalLength
// when written to buffer so no need to adjust it
- SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount, &fInitialDashLength,
- &fInitialDashIndex, &fIntervalLength);
+ SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount,
+ &fInitialDashLength, &fInitialDashIndex, &fIntervalLength);
}
}