Trying to be consistent when members are allowed to be NULL

Got a few crashes running the fuzzer locally, all related to handling NULL members/parameters in an inconsistent way.

BUG=skia:

Review URL: https://codereview.chromium.org/675013003
This commit is contained in:
sugoi 2014-10-30 14:05:14 -07:00 committed by Commit bot
parent e228ba3e5c
commit 9bde31e95d
3 changed files with 14 additions and 11 deletions

View File

@ -60,6 +60,10 @@ void SkLocalMatrixShader::toString(SkString* str) const {
#endif #endif
SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) { SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) {
if (NULL == proxy) {
return NULL;
}
if (localMatrix.isIdentity()) { if (localMatrix.isIdentity()) {
return SkRef(proxy); return SkRef(proxy);
} }

View File

@ -60,6 +60,9 @@ bool matrix_needs_clamping(SkScalar matrix[20]) {
SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf,
SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) {
SkASSERT(cf); SkASSERT(cf);
if (NULL == cf) {
return NULL;
}
SkScalar colorMatrix[20], inputMatrix[20]; SkScalar colorMatrix[20], inputMatrix[20];
SkColorFilter* inputColorFilter; SkColorFilter* inputColorFilter;
if (input && cf->asColorMatrix(colorMatrix) if (input && cf->asColorMatrix(colorMatrix)
@ -78,9 +81,7 @@ SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf,
SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID)
: INHERITED(1, &input, cropRect, uniqueID), fColorFilter(cf) { : INHERITED(1, &input, cropRect, uniqueID), fColorFilter(SkRef(cf)) {
SkASSERT(cf);
SkSafeRef(cf);
} }
#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
@ -102,7 +103,7 @@ void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
} }
SkColorFilterImageFilter::~SkColorFilterImageFilter() { SkColorFilterImageFilter::~SkColorFilterImageFilter() {
SkSafeUnref(fColorFilter); fColorFilter->unref();
} }
bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,

View File

@ -20,20 +20,18 @@ SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRe
flags = 0x0; flags = 0x0;
} }
CropRect cropRect(rect, flags); CropRect cropRect(rect, flags);
return SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)); return s ? SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)) : NULL;
} }
SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const CropRect* cropRect, uint32_t uniqueID) { SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const CropRect* cropRect, uint32_t uniqueID) {
SkASSERT(s); SkASSERT(s);
return SkNEW_ARGS(SkRectShaderImageFilter, (s, cropRect, uniqueID)); return s ? SkNEW_ARGS(SkRectShaderImageFilter, (s, cropRect, uniqueID)) : NULL;
} }
SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cropRect, SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cropRect,
uint32_t uniqueID) uint32_t uniqueID)
: INHERITED(0, NULL, cropRect, uniqueID) : INHERITED(0, NULL, cropRect, uniqueID)
, fShader(s) { , fShader(SkRef(s)) {
SkASSERT(s);
s->ref();
} }
#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
@ -55,7 +53,7 @@ void SkRectShaderImageFilter::flatten(SkWriteBuffer& buffer) const {
} }
SkRectShaderImageFilter::~SkRectShaderImageFilter() { SkRectShaderImageFilter::~SkRectShaderImageFilter() {
SkSafeUnref(fShader); fShader->unref();
} }
bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
@ -78,7 +76,7 @@ bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
SkPaint paint; SkPaint paint;
SkMatrix matrix(ctx.ctm()); SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())); matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matrix))->unref(); SkSafeUnref(paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matrix)));
SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height())); SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height()));
canvas.drawRect(rect, paint); canvas.drawRect(rect, paint);