From ce250a611ed92fbba4e318c336fcdc7434ba8e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 13 Jul 2022 11:48:26 +0200 Subject: [PATCH] Windows: fix error handling of syscall to AssocQueryStringW syscall.SyscallN returns a `uintptr` type alias, and thus has to be compared to `0`, not `nil`. Yeah, it's a bit weird. --- internal/worker/find_blender/windows.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/worker/find_blender/windows.go b/internal/worker/find_blender/windows.go index 95e06a86..8dec3c24 100644 --- a/internal/worker/find_blender/windows.go +++ b/internal/worker/find_blender/windows.go @@ -72,7 +72,7 @@ func fileAssociation(extension string) (string, error) { buf := make([]uint16, cchOut) pszOut := unsafe.Pointer(&buf[0]) - result1, _, err := syscall.SyscallN( + result1, _, errno := syscall.SyscallN( assocQueryString, uintptr(ASSOCF_INIT_DEFAULTTOSTAR), // [in] ASSOCF flags uintptr(ASSOCSTR_EXECUTABLE), // [in] ASSOCSTR str @@ -81,13 +81,8 @@ func fileAssociation(extension string) (string, error) { uintptr(pszOut), // [out, optional] LPWSTR pszOut uintptr(unsafe.Pointer(&cchOut)), // [in, out] DWORD *pcchOut ) - if err != nil { - // This can be a syscall.Errno with code 0, indicating things are actually fine. - if errno, ok := err.(syscall.Errno); ok && errno == 0 { - // So this is fine. - } else { - return "", fmt.Errorf("error calling AssocQueryStringW from shlwapi.dll: %w", err) - } + if errno != 0 { + return "", fmt.Errorf("error calling AssocQueryStringW from shlwapi.dll: %w", errno) } if result1 != 0 { return "", fmt.Errorf("unknown result %d calling AssocQueryStringW from shlwapi.dll: %w", result1, err)