internal/atlas: bug fix: possible overflowing on 32bit machines

Closes #2728
This commit is contained in:
Hajime Hoshi 2023-08-19 01:19:15 +09:00
parent 14c03e9aec
commit a5af6dc0a9

View File

@ -17,6 +17,7 @@ package atlas
import ( import (
"fmt" "fmt"
"image" "image"
"math"
"runtime" "runtime"
"sync" "sync"
@ -113,8 +114,10 @@ const baseCountToPutOnSourceBackend = 10
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error { func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
for i := range imagesToPutOnSourceBackend { for i := range imagesToPutOnSourceBackend {
i.usedAsSourceCount++ if i.usedAsSourceCount < math.MaxInt {
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.destinationCount, 31))) { i.usedAsSourceCount++
}
if int64(i.usedAsSourceCount) >= int64(baseCountToPutOnSourceBackend*(1<<uint(min(i.destinationCount, 31)))) {
if err := i.putOnSourceBackend(graphicsDriver); err != nil { if err := i.putOnSourceBackend(graphicsDriver); err != nil {
return err return err
} }