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: fmt.Sscanln doesn't error when given an incorrect bool to scan #68289

Closed
ncw opened this issue Jul 3, 2024 · 2 comments
Closed

fmt: fmt.Sscanln doesn't error when given an incorrect bool to scan #68289

ncw opened this issue Jul 3, 2024 · 2 comments

Comments

@ncw
Copy link
Contributor

ncw commented Jul 3, 2024

Go version

go version go1.21.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ncw/.cache/go-build'
GOENV='/home/ncw/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ncw/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ncw/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go/go1.21'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/go1.21/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4276667016=/tmp/go-build -gno-record-gcc-switches'

What did you do?

See: https://go.dev/play/p/UkzjB5-g2Fo

I ran

func main() {
	var o bool
	var in = "7"
	n, err := fmt.Sscanln(in, &o)
	fmt.Println(n, err)
	fmt.Println(o)
}

What did you see happen?

It produced

1 <nil>
false

Indicating that 1 argument had been successfully parsed as false.

What did you expect to see?

I expected to see this as I don't think "7" is a valid bool.

0 strconv.ParseBool: parsing "7": invalid syntax
false

Or possibly (but inconsistent with strconv.ParseBool)

1 <nil>
true
@gabyhelp
Copy link

gabyhelp commented Jul 3, 2024

@ncw
Copy link
Contributor Author

ncw commented Jul 3, 2024

Good bot :-) I think this is a dupe of #43306 which I managed to miss in my searching so I'll close this.

@ncw ncw closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants