Skip to content

Panic: invalid memory address or nil pointer dereference #541

Open
@NateDogg-MM

Description

@NateDogg-MM

I created a gist for it gist but the take away is it crashes when both structs have pointers, so

type botRet struct {
	Id            *string  `json:"id"`
	Name      string   `json:"name"`
	
}

var ret struct {
	Bot *botRet `json:"bot"`
}

but if at least one doesn't have the pointer, it works

type botRet struct {
	Id            string `json:"id"`
	Name      string `json:"name"`
	
}

or

var ret struct {
	Bot botRet `json:"bot"`
}

Here's the output of the error

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x24 pc=0x4cb674]

goroutine 1 [running]:
github.com/goccy/go-json/internal/encoder.appendNormalizedHTMLString({0xc0000d8400?, 0x0?, 0x0?}, {0x24, 0x52afb4})
        /root/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:73 +0xe34
github.com/goccy/go-json/internal/encoder.AppendString(0x0?, {0xc0000d8400?, 0x0?, 0x0?}, {0x24?, 0x0?})
        /root/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:52 +0x45
github.com/goccy/go-json/internal/encoder/vm.Run(0xc0000a2680, {0xc0000d8400?, 0x0?, 0x400?}, 0xc0000ac150?)
        /root/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:4541 +0x17cc3
github.com/goccy/go-json.encodeRunCode(0xc0000a2680?, {0xc0000d8400?, 0xc0000d1db0?, 0xc00009c200?}, 0xc0000d8800?)
        /root/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x56
github.com/goccy/go-json.encode(0xc0000a2680, {0x53b8a0, 0xc0000b0060})
        /root/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x205
github.com/goccy/go-json.marshal({0x53b8a0, 0xc0000b0060}, {0x0, 0x0, 0xc0000ae000?})
        /root/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xb9
github.com/goccy/go-json.MarshalWithOption(...)
        /root/go/pkg/mod/github.com/goccy/[email protected]/json.go:185
github.com/goccy/go-json.Marshal({0x53b8a0?, 0xc0000b0060?})
        /root/go/pkg/mod/github.com/goccy/[email protected]/json.go:170 +0x25
main.main()
        /var/www/go/json/json.go:29 +0x68
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions