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: not reporting bad index for the incorrect statement #15884

Closed
dlsniper opened this issue May 30, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@dlsniper
Copy link
Contributor

commented May 30, 2016

  1. What version of Go are you using (go version)?
    1.6.2
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
    The following code:
myWrongFormatVar := "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d"
log.Printf(myWrongFormatVar, 1, 2, 3, 4, 5, 6, 7, 8)

produces a BADINDEX at runtime however go vet doesn't catch it. To correct the code one should add a tenth argument to the Printf function and all should be ok.

In fact it should catch if the function has more than 9 other arguments (besides the formatting string) but it doesn't.

The other scenario is this:

log.Printf("%d %d %#[1]x %#x %f %2.f %2.2f %.f %.3f %[3]*.[2]*[1]f %d %d %#[1]x %#x %*[2]d %v % d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)

https://play.golang.org/p/snrXok614V

  1. What did you expect to see?
    An error about the BADINDEX
  2. What did you see instead?
    No error.
@dlsniper

This comment has been minimized.

Copy link
Contributor Author

commented May 30, 2016

Work on this is a bit more complicated as the initial patch only solves part of the problem, the indexing part still needs a bit more work.

@dlsniper

This comment has been minimized.

Copy link
Contributor Author

commented May 30, 2016

I have updated the description with the other bad case scenario.

@quentinmit quentinmit added this to the Unplanned milestone Jun 17, 2016

@quentinmit quentinmit added the NeedsFix label Jun 17, 2016

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2016

/cc @robpike @valyala based on recent commits

@robpike robpike self-assigned this Jun 17, 2016

@robpike robpike modified the milestones: Go1.8, Unplanned Jun 17, 2016

@valyala

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Jun 23, 2016

CL https://golang.org/cl/24391 mentions this issue.

@gopherbot gopherbot closed this in c9fbe0f Aug 29, 2016

@golang golang locked and limited conversation to collaborators Aug 29, 2017

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.