Commit 64e6fe2d authored by Dave Cheney's avatar Dave Cheney

image/draw: fix crash in clip

Fixes #9177

Change-Id: I1c7e57f0f0a9b00fb3ddc7fa4844ac53ea6df46f
Reviewed-on: https://go-review.googlesource.com/1876Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 01b25600
......@@ -191,3 +191,13 @@ func TestClip(t *testing.T) {
}
}
}
func TestClipWithNilMP(t *testing.T) {
src := image.NewRGBA(image.Rect(0, 0, 100, 100))
// dst must be smaller than src for clipping to occur
dst := image.NewRGBA(image.Rect(50, 50, 100, 100))
r := image.Rect(0, 0, 100, 100)
sp := image.ZP
// issue 9177: floydSteinberg.Draw passes nil for mp, which used to cause clip to panic
clip(dst, &r, src, &sp, nil, nil)
}
......@@ -83,8 +83,10 @@ func clip(dst Image, r *image.Rectangle, src image.Image, sp *image.Point, mask
}
(*sp).X += dx
(*sp).Y += dy
(*mp).X += dx
(*mp).Y += dy
if mp != nil {
(*mp).X += dx
(*mp).Y += dy
}
}
func processBackward(dst Image, r image.Rectangle, src image.Image, sp image.Point) bool {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment