internal/graphicsdriver/opengl: bug fix: potential infinite loop

This commit is contained in:
Hajime Hoshi 2023-03-23 02:47:23 +09:00
parent c27d191dd5
commit a19ff07130
2 changed files with 9 additions and 0 deletions

View File

@ -133,6 +133,10 @@ func (g *Graphics) SetUIView(uiview uintptr) {
}
func pow2(x uintptr) uintptr {
if x > (math.MaxUint+1)/2 {
return math.MaxUint
}
var p2 uintptr = 1
for p2 < x {
p2 *= 2

View File

@ -16,6 +16,7 @@ package opengl
import (
"fmt"
"math"
"runtime"
"unsafe"
@ -157,6 +158,10 @@ func (s *openGLState) reset(context *context) error {
}
func pow2(x int) int {
if x > (math.MaxInt+1)/2 {
return math.MaxInt
}
p2 := 1
for p2 < x {
p2 *= 2