]> Cypherpunks repositories - gostls13.git/commit
cmd/vet: don't suggest ... if it breaks a program
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 16 Aug 2018 13:39:13 +0000 (14:39 +0100)
committerRuss Cox <rsc@golang.org>
Fri, 17 Aug 2018 15:51:47 +0000 (15:51 +0000)
commit2482451f76f47707e29b19cafdcaf754badd024b
tree85ccd4f00bc359e64373ca392175cce1dd9f265b
parent876c6d1f274a3d508fa97558ca6765cf324c2939
cmd/vet: don't suggest ... if it breaks a program

It is possible to write a function that seems to wrap a print/printf
call, but then doesn't. For example, if the string parameter we thought
was the format is used as another argument.

One option would be to make vet's print analysis smarter, to detect when
format strings are indeed used like we initially suspected.

However, I've opted for a simpler solution - check if the print/printf
call is already using more than one variadic argument, in which case
using an ellipsis in the last one would break the program:

// too many arguments in call to fmt.Printf
fmt.Printf(format, arg0, args...)

Fixes #26979.

Change-Id: I39371f1cec8483cfd2770a91670c1e80cbb9efdf
Reviewed-on: https://go-review.googlesource.com/129575
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/vet/print.go
src/cmd/vet/testdata/print.go