Closed as not planned
Closed as not planned
Description
Go version
go version go1.21.5 windows/amd64
What operating system and processor architecture are you using (go env
)?
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\gopher\AppData\Local\go-build
set GOENV=C:\Users\gopher\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\gopher\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\gopher\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.5
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
go: stripping unprintable or unescapable characters from %"GOMOD"%
set GOMOD=C:\Users\gopher\a\b\code\testsyscallbug\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\gopher\AppData\Local\Temp\go-build1499209731=/tmp/go-build -gno-record-gcc-switches
What did you do?
package main
import (
"fmt"
"unsafe"
"golang.org/x/sys/windows"
)
type ACCEL struct {
Virt byte
Key uint16
Cmd uint16
}
func CreateAcceleratorTableW(accel []ACCEL) (uintptr, error) {
r, _, err := windows.NewLazySystemDLL("user32.dll").
NewProc("CreateAcceleratorTableW").
Call(uintptr(unsafe.Pointer(&accel[0])), uintptr(len(accel)))
if r == 0 {
return 0, err
}
return r, nil
}
func someAccels() []ACCEL {
return []ACCEL{{83, 13, 100}}
}
func main() {
var accels []ACCEL
accels = append(accels, someAccels()...)
h, err := CreateAcceleratorTableW(accels)
fmt.Println(h, err)
}
What did you expect to see?
handle_value <nil>
What did you see instead?
0 Invalid access to memory location.
But the weird thing is if I change the main function to the following, everything will be OK:
func main() {
var accels = make([]ACCEL, 0, 1)
accels = append(accels, someAccels()...)
h, err := CreateAcceleratorTableW(accels)
fmt.Println(h, err)
}