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

[BUG] Fatal error: invalid pointer found on stack #504

Closed
viewsharp opened this issue Apr 25, 2024 · 0 comments · Fixed by #505
Closed

[BUG] Fatal error: invalid pointer found on stack #504

viewsharp opened this issue Apr 25, 2024 · 0 comments · Fixed by #505

Comments

@viewsharp
Copy link
Contributor

When executing the following code:

package main

import (
	"testing"

	"github.com/goccy/go-json"
	"github.com/stretchr/testify/require"
)

type CustomMap map[string]any

func (m CustomMap) MarshalJSON() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	t := (map[string]interface{})(m)
	return json.Marshal(t)
}

func TestCustomMap(t *testing.T) {
	jsonData, err := json.Marshal([]CustomMap{
		{"foo": "bar"},
	})
	require.NoError(t, err)
	require.Equal(t, []byte(`[{"foo":"bar"}]`), jsonData)
}

The following error occurs:

runtime: bad pointer in frame github.com/goccy/go-json/internal/encoder/vm.Run at 0x14000161f90: 0x1
fatal error: invalid pointer found on stack

Runtime stack:
runtime_stack.log

Go version:
go version go1.20.4 darwin/arm64

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

Successfully merging a pull request may close this issue.

1 participant