From d1c764640da4b063d0d2d6989c6bed282c9e8e92 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 25 Aug 2021 02:08:07 +0900 Subject: [PATCH] internal/glfw, internal/graphicsdriver/opengl/gl: Use the last byte to detect a bool When a C function returns a bool value, only the first byte of a uintptr value matters. When we want to get a bool value from a C function, filter this for sefety. --- internal/glfw/glfw_windows.go | 6 +++--- internal/graphicsdriver/opengl/gl/package_windows.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index 60e88d30e..4a4ba6d37 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -301,7 +301,7 @@ func (w *Window) SetTitle(title string) { func (w *Window) ShouldClose() bool { r := glfwDLL.call("glfwWindowShouldClose", w.w) panicError() - return r == True + return byte(r) == True } func (w *Window) Show() { @@ -494,7 +494,7 @@ func Init() error { func (j Joystick) Present() bool { r := glfwDLL.call("glfwJoystickPresent", uintptr(j)) panicError() - return r == True + return byte(r) == True } func panicErrorExceptForInvalidValue() { @@ -556,7 +556,7 @@ func UpdateGamepadMappings(mapping string) bool { defer runtime.KeepAlive(m) r := glfwDLL.call("glfwUpdateGamepadMappings", uintptr(unsafe.Pointer(&m[0]))) panicError() - return r == True + return byte(r) == True } func WaitEvents() { diff --git a/internal/graphicsdriver/opengl/gl/package_windows.go b/internal/graphicsdriver/opengl/gl/package_windows.go index 10e5f5af4..ee406251b 100644 --- a/internal/graphicsdriver/opengl/gl/package_windows.go +++ b/internal/graphicsdriver/opengl/gl/package_windows.go @@ -315,22 +315,22 @@ func GetVertexArrayPointeri_vEXT(vaobj uint32, index uint32, pname uint32, param func IsFramebufferEXT(framebuffer uint32) bool { ret, _, _ := syscall.Syscall(gpIsFramebufferEXT, 1, uintptr(framebuffer), 0, 0) - return ret != 0 + return byte(ret) != 0 } func IsProgram(program uint32) bool { ret, _, _ := syscall.Syscall(gpIsProgram, 1, uintptr(program), 0, 0) - return ret != 0 + return byte(ret) != 0 } func IsRenderbufferEXT(renderbuffer uint32) bool { ret, _, _ := syscall.Syscall(gpIsRenderbufferEXT, 1, uintptr(renderbuffer), 0, 0) - return ret != 0 + return byte(ret) != 0 } func IsTexture(texture uint32) bool { ret, _, _ := syscall.Syscall(gpIsTexture, 1, uintptr(texture), 0, 0) - return ret != 0 + return byte(ret) != 0 } func LinkProgram(program uint32) {