Skip to content

fmt: stack overflow with recursive slice input and formatters %v/%#v #8241

@gopherbot

Description

@gopherbot

by 2852914:

What does 'go version' print?

go version go1.3 linux/amd64

What steps reproduce the problem?

Passing a slice that contains itself to a fmt.* function with either an implicit or
explicit %v formatter will result in an infinite recursion.

http://play.golang.org/p/qjG87yG_LA

What happened?

Infinite recursion inside the printing logic, stack limit reached.

What could have happened instead?

1. The documentation for fmt mentions this recursion caveat, being obvious it could
happen this is just for clarification.
2. The fmt functions need to keep track of what it has printed and not try to print
recursive values.
3. The fmt functions keep track of what it prints and panics (or error) with a more
sensible message when it detects recursion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions