restorable: Replace a potentially dangerous pointer usage

Getting a poniter to a loop variable is potentially dangerous.
This commit is contained in:
Hajime Hoshi 2020-12-20 13:28:13 +09:00
parent 2106e0fa6a
commit de14a44c01

View File

@ -84,14 +84,17 @@ func (rtp *rectToPixels) at(i, j int) (byte, byte, byte, byte, bool) {
var pix []byte var pix []byte
var r *image.Rectangle var r image.Rectangle
var found bool
if pt := image.Pt(i, j); pt.In(rtp.lastR) { if pt := image.Pt(i, j); pt.In(rtp.lastR) {
r = &rtp.lastR r = rtp.lastR
found = true
pix = rtp.lastPix pix = rtp.lastPix
} else { } else {
for rr := range rtp.m { for rr := range rtp.m {
if pt.In(rr) { if pt.In(rr) {
r = &rr r = rr
found = true
rtp.lastR = rr rtp.lastR = rr
pix = rtp.m[rr] pix = rtp.m[rr]
rtp.lastPix = pix rtp.lastPix = pix
@ -100,7 +103,7 @@ func (rtp *rectToPixels) at(i, j int) (byte, byte, byte, byte, bool) {
} }
} }
if r == nil { if !found {
return 0, 0, 0, 0, false return 0, 0, 0, 0, false
} }