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 r *image.Rectangle
var r image.Rectangle
var found bool
if pt := image.Pt(i, j); pt.In(rtp.lastR) {
r = &rtp.lastR
r = rtp.lastR
found = true
pix = rtp.lastPix
} else {
for rr := range rtp.m {
if pt.In(rr) {
r = &rr
r = rr
found = true
rtp.lastR = rr
pix = rtp.m[rr]
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
}