Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: invalid memory address or nil pointer dereference running go fmt #26792

Closed
trashhalo opened this issue Aug 3, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@trashhalo
Copy link

commented Aug 3, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +1b870077c8 Fri Aug 3 17:21:10 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

➜ echo go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/stephen/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/stephen/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/stephen/dev/go"
GOTMPDIR=""
GOTOOLDIR="/Users/stephen/dev/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/stephen/dev/echo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xs/bs09x7hj2jqb6hq3frfzrmkh0000gp/T/go-build052705807=/tmp/go-build -gno-record-gcc-switches -fno-commo

What did you do?

  1. go mod init.
  2. add a main.go missing a package line
  3. run go fmt
import (
	"net/http"

	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
)

func main() {
	// Echo instance
	e := echo.New()

	// Middleware
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// Route => handler
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!\n")
	})

	// Start server
	e.Logger.Fatal(e.Start(":1323"))
}

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

it to yell at me about the package line

What did you see instead?

➜  echo go fmt main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1452c47]

goroutine 1 [running]:
cmd/go/internal/fmtcmd.runFmt(0x194de80, 0xc0000a60b0, 0x1, 0x1)
	/Users/stephen/dev/go/src/cmd/go/internal/fmtcmd/fmt.go:63 +0x1b7
main.main()
	/Users/stephen/dev/go/src/cmd/go/main.go:218 +0x7d4

@ianlancetaylor ianlancetaylor changed the title go fmt invalid memory address or nil pointer dereference cmd/gofmt: invalid memory address or nil pointer dereference Aug 3, 2018

@ianlancetaylor ianlancetaylor changed the title cmd/gofmt: invalid memory address or nil pointer dereference cmd/go: invalid memory address or nil pointer dereference running go fmt Aug 3, 2018

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Aug 3, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Aug 3, 2018

Change https://golang.org/cl/127856 mentions this issue: cmd/go: don't crash in go fmt on invalid input when using modules

@gopherbot gopherbot closed this in 07bcfe5 Aug 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.