Commit 31246223 authored by Shenghou Ma's avatar Shenghou Ma Committed by Andrew Gerrand

[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 <minux@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
parent a2556457
......@@ -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)
......
......@@ -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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment