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: crash stack overflow / size exceeded when printing value of self referencing structure #2850

Open
MikaelVallenet opened this issue Sep 26, 2024 · 2 comments · May be fixed by #2851
Open

Comments

@MikaelVallenet
Copy link
Contributor

MikaelVallenet commented Sep 26, 2024

crash stack overflow when printing value of self referencing struct

Description

When a structure refers to itself (e.g. linked list, tree ...etc), printing its value with %v flag causes the VM to crash.
In go this program displays &{user [] [] <nil> <nil>} and run with no problem.

Related: #1315

program:

package main

import "fmt"

type Role struct {
	Name        string
	Permissions []string
	Users       []string
	Next        *Role
	Prev        *Role
}

func main() {
	userRole := &Role{
		Name:        "user",
		Permissions: []string{},
		Users:       []string{},
		Next:        nil,
		Prev:        nil,
	}

	fmt.Printf("%v", userRole)
}

Your environment

  • Go version: 1.17
  • OS and CPU architecture: linux/amd64

Expected behaviour

print &{user [] [] <nil> <nil>}

Actual behaviour

crash w/ stack overflow

Proposed solution

I think it could come from infinite recursive on self referencing struct, i would like to assign myself to the issue and work on a fix in the next days 🚀

@thehowl
Copy link
Member

thehowl commented Sep 26, 2024

thanks for tackling this!

@moul
Copy link
Member

moul commented Sep 27, 2024

Go version: 1.17

is the project still working on this version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
3 participants