diff options
-rw-r--r-- | src/runtime/syscall_windows.go | 10 | ||||
-rw-r--r-- | src/runtime/syscall_windows_test.go | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go index 5b76ad573c..51004b78a0 100644 --- a/src/runtime/syscall_windows.go +++ b/src/runtime/syscall_windows.go @@ -54,11 +54,13 @@ func compileCallback(fn eface, cleanstack bool) (code uintptr) { panic("compilecallback: output parameter size is wrong") } argsize := uintptr(0) - for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] { - if (*t).size > uintptrSize { - panic("compilecallback: input parameter size is wrong") + if len(ft.in) > 0 { + for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] { + if (*t).size > uintptrSize { + panic("compilecallback: input parameter size is wrong") + } + argsize += uintptrSize } - argsize += uintptrSize } lock(&cbs.lock) diff --git a/src/runtime/syscall_windows_test.go b/src/runtime/syscall_windows_test.go index ce8a9ec1ba..126bef62ef 100644 --- a/src/runtime/syscall_windows_test.go +++ b/src/runtime/syscall_windows_test.go @@ -533,3 +533,11 @@ func main() { println(z) } ` + +func TestCallbackWithNoInputParameters(t *testing.T) { + // Test that NewCallback and NewCallbackCDecl can accept functions without + // input parameters, see issue 9871. + cb := func() uintptr { return 0 } + _ = syscall.NewCallback(cb) + _ = syscall.NewCallbackCDecl(cb) +} |