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

cmd/vet: no or incorrect warning for zero-based indexing in printf format #9752

Closed
jstemmer opened this issue Feb 2, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@jstemmer
Copy link
Contributor

commented Feb 2, 2015

Using go1.4.1 linux/amd64 and golang.org/x/tools 1afe783e9f23b46389ab7a439ed4e0eee558382a.

Run the following source (playground link) and then run go vet on the same file:

fmt.Printf("%[0]s\n", "arg1")
fmt.Printf("%[0]d\n", 1)

You'll see the following output:

$ go run vet.go
%!s(BADINDEX)
%!d(BADINDEX)

$ go vet vet.go
vet.go:9: arg "%[0]d\n" for printf verb %d of wrong type: string
exit status 1

There was no warning for the first format and a misleading warning for the second format.

vet does warn for negative or out of bounds indices, so for consistency I think it should also warn that indices are one-based.

@mikioh mikioh added the repo-tools label Feb 2, 2015

@jstemmer

This comment has been minimized.

Copy link
Contributor Author

commented Feb 2, 2015

@jstemmer

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2015

@jstemmer jstemmer closed this Feb 4, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.