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

toml.Unmarshal overrides origin values even if not export field #283

Closed
For-ACGN opened this issue Jun 11, 2019 · 3 comments
Closed

toml.Unmarshal overrides origin values even if not export field #283

For-ACGN opened this issue Jun 11, 2019 · 3 comments
Labels
bug Issues describing a bug in go-toml.

Comments

@For-ACGN
Copy link

Describe the bug
toml.Unmarshal overrides origin values even if not export field

To Reproduce

package main

import (
	"fmt"
	"log"

	"github.com/pelletier/go-toml"
)

type Ti interface {
	Print()
}

type tii struct {
	A string
}

func (this *tii) Print() {
	fmt.Print(this.A)
}

type S struct {
	A  string
	ti Ti
	tp *tii
}

func main() {
	ti := new(tii)
	tp := new(tii)
	s := &S{A: "asd", ti: ti, tp: tp}
	b, err := toml.Marshal(s)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("%p %p %p \n", &s.A, s.ti, s.tp)
	toml.Unmarshal(b, s)
	fmt.Printf("%p %p %p \n", &s.A, s.ti, s.tp)
	ti.Print()
	tp.Print()
	s.ti.Print()
	s.tp.Print()
}

print

0xc0000884e0 0xc00005e4c0 0xc00005e4d0
0xc0000884e0 %!p(<nil>) 0x0
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x4eea54]

goroutine 1 [running]:
main.main()
        E:/Project/toml bug/toml.go:41 +0x4a4
exit status 2

Expected behavior
not set nil

Versions

  • go-toml: v1.4.0 and dba45d4
  • go: version 1.12.5
  • operating system: Windows
@pelletier pelletier added the bug Issues describing a bug in go-toml. label Jul 17, 2019
@pelletier
Copy link
Owner

Thanks for the bug report! Looks like #284 will fix that problem as soon as it's merged (it does work for this specific example).

@pelletier
Copy link
Owner

@For-ACGN #284 has been merged. Do you mind giving this another shot to make sure the bug is fixed for you?

@For-ACGN
Copy link
Author

@pelletier @roberth-k
Oh! It fix this bug and works right. Thank you!
https://github.com/For-ACGN/go-toml-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug in go-toml.
Projects
None yet
Development

No branches or pull requests

2 participants