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

Panic on customized Stringer of map #115

Open
wwwjfy opened this issue Sep 10, 2019 · 2 comments
Open

Panic on customized Stringer of map #115

wwwjfy opened this issue Sep 10, 2019 · 2 comments

Comments

@wwwjfy
Copy link

wwwjfy commented Sep 10, 2019

Hi, I've come across this issue, that with the pointer method feature, the address is updated to 0x1.

Demonstration:

package main

import (
	"fmt"

	"github.com/davecgh/go-spew/spew"
)

type myMap map[int64]int64

func (c myMap) String() string {
	fmt.Printf("pointer changed: %p\n", c)
	for k := range c {
		fmt.Println(k)
	}

	return "custom string"
}

func main() {
	spew.Printf("%v\n", myMap{1: 1})
}

It gives me

$ go run main.go
pointer changed: 0x1
(PANIC=runtime error: invalid memory address or nil pointer dereference)map[1:1]

With spew.Config.DisablePointerMethods = true, the panic is gone.

@jrick
Copy link
Contributor

jrick commented Sep 26, 2019

This is also fixed by building with the safe build tag. Appears to be a memory unsafety issue introduced by spew making some assumptions about the newer Go release.

@dwlnetnl
Copy link

I've fixed this in my fork of the package: spewerspew/spew@62a6506

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants