Skip to content

panic since v1.9.0 with nil string pointer #272

Description

@jerome-laforge

with this code:

func TestNilStringPointer(t *testing.T) {
	var s *string
	t.Log(cast.ToStringE(s))
}

got a recursive deadlock:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020602398 stack=[0xc020602000, 0xc040602000]
fatal error: stack overflow

goroutine 20 gp=0xc0005828c0 m=0 mp=0x122e5e0 [running]:
reflect.valueInterface({0xa84060?, 0x0?, 0x16?}, 0x1?)
	go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.3.linux-amd64/src/reflect/value.go:1487 +0x115 fp=0xc0206023a8 sp=0xc0206023a0 pc=0x4f0a15
reflect.Value.Interface(...)
	go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.3.linux-amd64/src/reflect/value.go:1484
github.com/spf13/cast.indirect({0xa84060, 0x0})
	go/pkg/mod/github.com/spf13/cast@v1.9.0/indirect.go:31 +0x11a fp=0xc0206023f8 sp=0xc0206023a8 pc=0x78887a
github.com/spf13/cast.ToStringE({0xa84060, 0x0})
	go/pkg/mod/github.com/spf13/cast@v1.9.0/basic.go:121 +0x49f fp=0xc020602480 sp=0xc0206023f8 pc=0x78865f
github.com/spf13/cast.ToStringE({0xa84060, 0x0})
	go/pkg/mod/github.com/spf13/cast@v1.9.0/basic.go:122 +0x53e fp=0xc020602508 sp=0xc020602480 pc=0x7886fe
github.com/spf13/cast.ToStringE({0xa84060, 0x0})
	go/pkg/mod/github.com/spf13/cast@v1.9.0/basic.go:122 +0x53e fp=0xc020602590 sp=0xc020602508 pc=0x7886fe

want empty string

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions