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
Closed

Comments

@jstemmer
Copy link
Contributor

jstemmer 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.

@jstemmer
Copy link
Contributor Author

jstemmer commented Feb 2, 2015

Proposed fix: https://go-review.googlesource.com/#/c/3692/

@jstemmer
Copy link
Contributor Author

jstemmer commented Feb 4, 2015

Fixed in golang/tools@913f41f

@jstemmer jstemmer closed this as completed 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.
Projects
None yet
Development

No branches or pull requests

3 participants