Skip to content

Commit 2353c15

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 32dfd69 commit 2353c15

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/cmd/cgo/internal/test/test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ func testErrno(t *testing.T) {
10961096
}
10971097

10981098
func testMultipleAssign(t *testing.T) {
1099+
if runtime.GOOS == "windows" && usesUCRT(t) {
1100+
// UCRT's strtol throws an unrecoverable crash when
1101+
// using an invalid base (that is, not 0 or 2..36).
1102+
// See go.dev/issue/62887.
1103+
t.Skip("skipping test on Windows when linking with UCRT")
1104+
}
10991105
p := C.CString("234")
11001106
n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10)
11011107
defer C.free(unsafe.Pointer(p))

src/cmd/cgo/internal/test/test_unix.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
package cgotest
88

9-
import "syscall"
9+
import (
10+
"syscall"
11+
"testing"
12+
)
1013

1114
var syscall_dot_SIGCHLD = syscall.SIGCHLD
15+
16+
func usesUCRT(t *testing.T) bool {
17+
return false
18+
}

src/cmd/cgo/internal/test/test_windows.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
package cgotest
66

7-
import "syscall"
7+
import (
8+
"internal/syscall/windows"
9+
"syscall"
10+
"testing"
11+
)
812

913
var syscall_dot_SIGCHLD syscall.Signal
14+
15+
// usesUCRT reports whether the test is using the Windows UCRT (Universal C Runtime).
16+
func usesUCRT(t *testing.T) bool {
17+
name, err := syscall.UTF16PtrFromString("ucrtbase.dll")
18+
if err != nil {
19+
t.Fatal(err)
20+
}
21+
h, err := windows.GetModuleHandle(name)
22+
return err == nil && h != 0
23+
}

0 commit comments

Comments
 (0)