mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
restorable: Replace a potentially dangerous pointer usage
Getting a poniter to a loop variable is potentially dangerous.
This commit is contained in:
parent
2106e0fa6a
commit
de14a44c01
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user