Skip to content

Commit 892b507

Browse files
committed
fmt: document that self-recursive data structures can be fatal
Fixes #8241. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/144420043
1 parent 1392276 commit 892b507

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/fmt/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
func (x X) String() string { return Sprintf("<%s>", x) }
148148
convert the value before recurring:
149149
func (x X) String() string { return Sprintf("<%s>", string(x)) }
150+
Infinite recursion can also be triggered by self-referential data
151+
structures, such as a slice that contains itself as an element, if
152+
that type has a String method. Such pathologies are rare, however,
153+
and the package does not protect against them.
150154
151155
Explicit argument indexes:
152156

0 commit comments

Comments
 (0)