Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.15 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\SESA571965\AppData\Local\go-build set GOENV=C:\Users\SESA571965\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\SESA571965\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\SESA571965\go set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=c:\go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=c:\go\pkg\tool\windows_amd64 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=C:\Users\SESA571965\Documents\EdgeCore.omar\go.mod set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\SESA57~1\AppData\Local\Temp\go-build806356266=/tmp/go-build -gno-record-gcc-switches
What did you do?
Code to reproduce it
package main
import (
"bytes"
"fmt"
"net/http"
)
func main() {
var body *bytes.Buffer
_, _ = http.NewRequest("GET", "https://google.fr/", body)
fmt.Println("Hello, playground")
}
What did you expect to see?
I want to have the same behaviour when I run this code
package main
import (
"fmt"
"net/http"
)
func main() {
_, _ = http.NewRequest("GET", "https://google.fr/", nil)
fmt.Println("Hello, playground")
}
What did you see instead?
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x546824]
goroutine 1 [running]:
bytes.(*Buffer).Len(...)
/usr/local/go-faketime/src/bytes/buffer.go:73
net/http.NewRequestWithContext(0x5cc7a0, 0xc0000b8020, 0x59583d, 0x3, 0x598c4f, 0x12, 0x5ca900, 0x0, 0x0, 0x0, ...)
/usr/local/go-faketime/src/net/http/request.go:875 +0x524
net/http.NewRequest(...)
/usr/local/go-faketime/src/net/http/request.go:813
main.main()
/tmp/sandbox461295219/prog.go:11 +0x7c