From: Shenghou Ma Date: Tue, 17 Feb 2015 04:43:40 +0000 (-0500) Subject: [release-branch.go1.4] runtime: don't panic when given a callback with no input param... X-Git-Tag: go1.4.2~5 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3124622303cd50e9b5965ea4dd68ef294e1a4404;p=gostls13.git [release-branch.go1.4] runtime: don't panic when given a callback with no input params on windows Fixes #9871 for Go 1.4. Change-Id: I550a5bdb29e9a872652e0dd468a434227d7d9502 Reviewed-on: https://go-review.googlesource.com/4937 Run-TryBot: Minux Ma Reviewed-by: Rob Pike Reviewed-by: Alex Brainman Reviewed-by: Andrew Gerrand --- 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) +}