From: qmuntal Date: Fri, 19 Sep 2025 10:18:26 +0000 (+0200) Subject: cmd/cgo/internal/test: skip TestMultipleAssign when using UCRT on Windows X-Git-Tag: go1.26rc1~819 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2353c1578596aae7128f028c75b52c6047f0b057;p=gostls13.git cmd/cgo/internal/test: skip TestMultipleAssign when using UCRT on Windows The Universal C Runtime (UCRT) default behavior is to crash the program when strtol is called with an invalid base (that is, not 0 or 2..36). This an invalid base (that is, not 0 or 2..36). This changes the test to skip when running on Windows and linking with UCRT. When using external linking mode this test passes if using the Mingw-w64 toolchain, even when linking with UCRT. That's because the Mingw-w64 linker adds a _set_invalid_parameter_handler call at startup that overrides the default UCRT behavior. However, other toolchains, like MSVC and LLVM, doesn't override the default behavior. Overriding the default behavior is out of the scope for this test, so the test is skipped instead. Fixes #62887 Change-Id: I60f140faf0eda80a2de4e10876be25e0dbe442d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/705455 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- diff --git a/src/cmd/cgo/internal/test/test.go b/src/cmd/cgo/internal/test/test.go index fb4a8250a2..9626407d88 100644 --- a/src/cmd/cgo/internal/test/test.go +++ b/src/cmd/cgo/internal/test/test.go @@ -1096,6 +1096,12 @@ func testErrno(t *testing.T) { } func testMultipleAssign(t *testing.T) { + if runtime.GOOS == "windows" && usesUCRT(t) { + // UCRT's strtol throws an unrecoverable crash when + // using an invalid base (that is, not 0 or 2..36). + // See go.dev/issue/62887. + t.Skip("skipping test on Windows when linking with UCRT") + } p := C.CString("234") n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10) defer C.free(unsafe.Pointer(p)) diff --git a/src/cmd/cgo/internal/test/test_unix.go b/src/cmd/cgo/internal/test/test_unix.go index 664c4850d3..9f35583125 100644 --- a/src/cmd/cgo/internal/test/test_unix.go +++ b/src/cmd/cgo/internal/test/test_unix.go @@ -6,6 +6,13 @@ package cgotest -import "syscall" +import ( + "syscall" + "testing" +) var syscall_dot_SIGCHLD = syscall.SIGCHLD + +func usesUCRT(t *testing.T) bool { + return false +} diff --git a/src/cmd/cgo/internal/test/test_windows.go b/src/cmd/cgo/internal/test/test_windows.go index 7bfb33a83c..c6f31430cf 100644 --- a/src/cmd/cgo/internal/test/test_windows.go +++ b/src/cmd/cgo/internal/test/test_windows.go @@ -4,6 +4,20 @@ package cgotest -import "syscall" +import ( + "internal/syscall/windows" + "syscall" + "testing" +) var syscall_dot_SIGCHLD syscall.Signal + +// usesUCRT reports whether the test is using the Windows UCRT (Universal C Runtime). +func usesUCRT(t *testing.T) bool { + name, err := syscall.UTF16PtrFromString("ucrtbase.dll") + if err != nil { + t.Fatal(err) + } + h, err := windows.GetModuleHandle(name) + return err == nil && h != 0 +}