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

fmt: stack overflow #15690

CodyGuo opened this issue May 15, 2016 · 3 comments

fmt: stack overflow #15690

CodyGuo opened this issue May 15, 2016 · 3 comments


Copy link

@CodyGuo CodyGuo commented May 15, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6 windows/386
  2. What operating system and processor architecture are you using (go env)?
    set GOARCH=386
    set GOBIN=D:\go\bin
    set GOEXE=.exe
    set GOHOSTARCH=386
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=D:\go\gopath;D:\go\cpath
    set GORACE=
    set GOROOT=D:\go
    set GOTOOLDIR=D:\go\pkg\tool\windows_386
    set CC=gcc
    set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0
    set CXX=g++
    set CGO_ENABLED=1
  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on is best.


package main

import (

type Str string

func (s Str) String() string {
    return fmt.Sprintf("Str: %s", s)

func main() {
    var s Str = "hi"
  1. What did you expect to see?
    Str: hi
  2. What did you see instead?
    runtime: goroutine stack exceeds 250000000-byte limit
    fatal error: stack overflow

runtime stack:
runtime.throw(0x4e33b0, 0xe)
D:/go/src/runtime/panic.go:530 +0x7f
D:/go/src/runtime/stack.go:940 +0x9a7
D:/go/src/runtime/asm_386.s:382 +0x6f

goroutine 1 [stack growth]:
runtime.heapBitsSetType(0x1270c200, 0x8, 0x8, 0x4c1860)
D:/go/src/runtime/mbitmap.go:679 fp=0x18b10a7c sp=0x18b10a78
runtime.mallocgc(0x8, 0x4c1860, 0x0, 0x0)
D:/go/src/runtime/malloc.go:682 +0x58a fp=0x18b10ae8 sp=0x18b10a7c
runtime.newobject(0x4c1860, 0x54d17c)
D:/go/src/runtime/malloc.go:781 +0x41 fp=0x18b10afc sp=0x18b10ae8
runtime.convT2E(0x4c1860, 0x18b10b3c, 0x0, 0x0, 0x0)
D:/go/src/runtime/iface.go:140 +0x89 fp=0x18b10b10 sp=0x18b10afc
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0x7a fp=0x18b10b54 sp=0x18b10b10
main.(_Str).String(0x1270c1f8, 0x0, 0x0)
:1 +0x8d fp=0x18b10b70 sp=0x18b10b54
fmt.(_pp).handleMethods(0x1270f200, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b10be0 sp=0x18b10b70
fmt.(_pp).printArg(0x1270f200, 0x4c1860, 0x1270c1f8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b10cc8 sp=0x18b10be0
fmt.(_pp).doPrintf(0x1270f200, 0x4d6bf0, 0x7, 0x18b10edc, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b10e90 sp=0x18b10cc8
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b10edc, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b10eb8 sp=0x18b10e90
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b10efc sp=0x18b10eb8
main.(_Str).String(0x1270c1f0, 0x0, 0x0)
:1 +0x8d fp=0x18b10f18 sp=0x18b10efc
fmt.(_pp).handleMethods(0x1270f170, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b10f88 sp=0x18b10f18
fmt.(_pp).printArg(0x1270f170, 0x4c1860, 0x1270c1f0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b11070 sp=0x18b10f88
fmt.(_pp).doPrintf(0x1270f170, 0x4d6bf0, 0x7, 0x18b11284, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b11238 sp=0x18b11070
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b11284, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b11260 sp=0x18b11238
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b112a4 sp=0x18b11260
main.(_Str).String(0x1270c1e8, 0x0, 0x0)
:1 +0x8d fp=0x18b112c0 sp=0x18b112a4
fmt.(_pp).handleMethods(0x1270f0e0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b11330 sp=0x18b112c0
fmt.(_pp).printArg(0x1270f0e0, 0x4c1860, 0x1270c1e8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b11418 sp=0x18b11330
fmt.(_pp).doPrintf(0x1270f0e0, 0x4d6bf0, 0x7, 0x18b1162c, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b115e0 sp=0x18b11418
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b1162c, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b11608 sp=0x18b115e0
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b1164c sp=0x18b11608
main.(_Str).String(0x1270c1e0, 0x0, 0x0)
:1 +0x8d fp=0x18b11668 sp=0x18b1164c
fmt.(_pp).handleMethods(0x1270f050, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b116d8 sp=0x18b11668
fmt.(_pp).printArg(0x1270f050, 0x4c1860, 0x1270c1e0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b117c0 sp=0x18b116d8
fmt.(_pp).doPrintf(0x1270f050, 0x4d6bf0, 0x7, 0x18b119d4, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b11988 sp=0x18b117c0
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b119d4, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b119b0 sp=0x18b11988
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b119f4 sp=0x18b119b0
main.(_Str).String(0x1270c1d8, 0x0, 0x0)
:1 +0x8d fp=0x18b11a10 sp=0x18b119f4
fmt.(_pp).handleMethods(0x1270efc0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b11a80 sp=0x18b11a10
fmt.(_pp).printArg(0x1270efc0, 0x4c1860, 0x1270c1d8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b11b68 sp=0x18b11a80
fmt.(_pp).doPrintf(0x1270efc0, 0x4d6bf0, 0x7, 0x18b11d7c, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b11d30 sp=0x18b11b68
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b11d7c, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b11d58 sp=0x18b11d30
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b11d9c sp=0x18b11d58
main.(_Str).String(0x1270c1d0, 0x0, 0x0)
:1 +0x8d fp=0x18b11db8 sp=0x18b11d9c
fmt.(_pp).handleMethods(0x1270ef30, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b11e28 sp=0x18b11db8
fmt.(_pp).printArg(0x1270ef30, 0x4c1860, 0x1270c1d0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b11f10 sp=0x18b11e28
fmt.(_pp).doPrintf(0x1270ef30, 0x4d6bf0, 0x7, 0x18b12124, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b120d8 sp=0x18b11f10
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b12124, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b12100 sp=0x18b120d8
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b12144 sp=0x18b12100
main.(_Str).String(0x1270c1c8, 0x0, 0x0)
:1 +0x8d fp=0x18b12160 sp=0x18b12144
fmt.(_pp).handleMethods(0x1270eea0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b121d0 sp=0x18b12160
fmt.(_pp).printArg(0x1270eea0, 0x4c1860, 0x1270c1c8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b122b8 sp=0x18b121d0
fmt.(_pp).doPrintf(0x1270eea0, 0x4d6bf0, 0x7, 0x18b124cc, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b12480 sp=0x18b122b8
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b124cc, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b124a8 sp=0x18b12480
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b124ec sp=0x18b124a8
main.(_Str).String(0x1270c1c0, 0x0, 0x0)
:1 +0x8d fp=0x18b12508 sp=0x18b124ec
fmt.(_pp).handleMethods(0x1270ee10, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b12578 sp=0x18b12508
fmt.(_pp).printArg(0x1270ee10, 0x4c1860, 0x1270c1c0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b12660 sp=0x18b12578
fmt.(_pp).doPrintf(0x1270ee10, 0x4d6bf0, 0x7, 0x18b12874, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b12828 sp=0x18b12660
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b12874, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b12850 sp=0x18b12828
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b12894 sp=0x18b12850
main.(_Str).String(0x1270c1b8, 0x0, 0x0)
:1 +0x8d fp=0x18b128b0 sp=0x18b12894
fmt.(_pp).handleMethods(0x1270ed80, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b12920 sp=0x18b128b0
fmt.(_pp).printArg(0x1270ed80, 0x4c1860, 0x1270c1b8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b12a08 sp=0x18b12920
fmt.(_pp).doPrintf(0x1270ed80, 0x4d6bf0, 0x7, 0x18b12c1c, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b12bd0 sp=0x18b12a08
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b12c1c, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b12bf8 sp=0x18b12bd0
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b12c3c sp=0x18b12bf8
main.(_Str).String(0x1270c1b0, 0x0, 0x0)
:1 +0x8d fp=0x18b12c58 sp=0x18b12c3c
fmt.(_pp).handleMethods(0x1270ecf0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b12cc8 sp=0x18b12c58
fmt.(_pp).printArg(0x1270ecf0, 0x4c1860, 0x1270c1b0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b12db0 sp=0x18b12cc8
fmt.(_pp).doPrintf(0x1270ecf0, 0x4d6bf0, 0x7, 0x18b12fc4, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b12f78 sp=0x18b12db0
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b12fc4, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b12fa0 sp=0x18b12f78
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b12fe4 sp=0x18b12fa0
main.(_Str).String(0x1270c1a8, 0x0, 0x0)
:1 +0x8d fp=0x18b13000 sp=0x18b12fe4
fmt.(_pp).handleMethods(0x1270ec60, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b13070 sp=0x18b13000
fmt.(_pp).printArg(0x1270ec60, 0x4c1860, 0x1270c1a8, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b13158 sp=0x18b13070
fmt.(_pp).doPrintf(0x1270ec60, 0x4d6bf0, 0x7, 0x18b1336c, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b13320 sp=0x18b13158
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b1336c, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b13348 sp=0x18b13320
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b1338c sp=0x18b13348
main.(_Str).String(0x1270c1a0, 0x0, 0x0)
:1 +0x8d fp=0x18b133a8 sp=0x18b1338c
fmt.(_pp).handleMethods(0x1270ebd0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b13418 sp=0x18b133a8
fmt.(_pp).printArg(0x1270ebd0, 0x4c1860, 0x1270c1a0, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b13500 sp=0x18b13418
fmt.(_pp).doPrintf(0x1270ebd0, 0x4d6bf0, 0x7, 0x18b13714, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b136c8 sp=0x18b13500
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b13714, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b136f0 sp=0x18b136c8
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b13734 sp=0x18b136f0
main.(_Str).String(0x1270c198, 0x0, 0x0)
:1 +0x8d fp=0x18b13750 sp=0x18b13734
fmt.(_pp).handleMethods(0x1270eb40, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b137c0 sp=0x18b13750
fmt.(_pp).printArg(0x1270eb40, 0x4c1860, 0x1270c198, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b138a8 sp=0x18b137c0
fmt.(_pp).doPrintf(0x1270eb40, 0x4d6bf0, 0x7, 0x18b13abc, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b13a70 sp=0x18b138a8
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b13abc, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b13a98 sp=0x18b13a70
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b13adc sp=0x18b13a98
main.(_Str).String(0x1270c190, 0x0, 0x0)
:1 +0x8d fp=0x18b13af8 sp=0x18b13adc
fmt.(_pp).handleMethods(0x1270eab0, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b13b68 sp=0x18b13af8
fmt.(_pp).printArg(0x1270eab0, 0x4c1860, 0x1270c190, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b13c50 sp=0x18b13b68
fmt.(_pp).doPrintf(0x1270eab0, 0x4d6bf0, 0x7, 0x18b13e64, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b13e18 sp=0x18b13c50
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b13e64, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b13e40 sp=0x18b13e18
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b13e84 sp=0x18b13e40
main.(_Str).String(0x1270c188, 0x0, 0x0)
:1 +0x8d fp=0x18b13ea0 sp=0x18b13e84
fmt.(_pp).handleMethods(0x1270ea20, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b13f10 sp=0x18b13ea0
fmt.(_pp).printArg(0x1270ea20, 0x4c1860, 0x1270c188, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b13ff8 sp=0x18b13f10
fmt.(_pp).doPrintf(0x1270ea20, 0x4d6bf0, 0x7, 0x18b1420c, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b141c0 sp=0x18b13ff8
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b1420c, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b141e8 sp=0x18b141c0
main.Str.String(0x4d6264, 0x2, 0x0, 0x0)
0 +0xc9 fp=0x18b1422c sp=0x18b141e8
main.(_Str).String(0x1270c180, 0x0, 0x0)
:1 +0x8d fp=0x18b14248 sp=0x18b1422c
fmt.(_pp).handleMethods(0x1270e990, 0x73, 0x0, 0x1)
D:/go/src/fmt/print.go:730 +0x4ba fp=0x18b142b8 sp=0x18b14248
fmt.(_pp).printArg(0x1270e990, 0x4c1860, 0x1270c180, 0x73, 0x0, 0x0)
D:/go/src/fmt/print.go:806 +0x422 fp=0x18b143a0 sp=0x18b142b8
fmt.(_pp).doPrintf(0x1270e990, 0x4d6bf0, 0x7, 0x18b145b4, 0x1, 0x1)
D:/go/src/fmt/print.go:1238 +0x198c fp=0x18b14568 sp=0x18b143a0
fmt.Sprintf(0x4d6bf0, 0x7, 0x18b145b4, 0x1, 0x1, 0x0, 0x0)
D:/go/src/fmt/print.go:203 +0x5f fp=0x18b14590 sp=0x18b14568
...additional frames elided...

Copy link

@dominikh dominikh commented May 15, 2016

You are implementing Str.String in terms of itself. return fmt.Sprintf("Str: %s", s) will call s.String(), resulting in infinite recursion. Convert s to string first.

Copy link

@davecheney davecheney commented May 15, 2016

This is working as intended, you are using the %s verb to call Str's String method, which uses fmt.Sprint to call Str's String method, and so on.

In future please ask questions like this on the forum or mailing list. If there is a bug, you'll be directed to raise an issue here.


@davecheney davecheney closed this May 15, 2016
Copy link

@CodyGuo CodyGuo commented May 15, 2016

@dominikh @davecheney Thank you, for other reasons, I can't access to the forum .

@golang golang locked and limited conversation to collaborators May 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.