]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/test: skip TestMultipleAssign when using UCRT on Windows
authorqmuntal <quimmuntal@gmail.com>
Fri, 19 Sep 2025 10:18:26 +0000 (12:18 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 22 Sep 2025 15:26:41 +0000 (08:26 -0700)
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 <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/cgo/internal/test/test.go
src/cmd/cgo/internal/test/test_unix.go
src/cmd/cgo/internal/test/test_windows.go

index fb4a8250a2666f98ead6ac2ca08e083efb5bb753..9626407d882ef2b4222fbd77339213b2e467d8dc 100644 (file)
@@ -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))
index 664c4850d387231a8403ae4184c362198ce52a24..9f355831256c6f3ee360f89e2f9d4a17a98c8686 100644 (file)
@@ -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
+}
index 7bfb33a83c3787a319d9b2a448034a5ec89a3568..c6f31430cf4b20b1f80a07ba532c97c361d6f767 100644 (file)
@@ -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
+}