@@ -68,12 +68,12 @@ type printfExport struct {
68
68
var printfImported = make (map [string ]map [string ]int )
69
69
70
70
type printfWrapper struct {
71
- name string
72
- fn * ast.FuncDecl
73
- format * ast.Field
74
- args * ast.Field
75
- callers []printfCaller
76
- printfLike bool
71
+ name string
72
+ fn * ast.FuncDecl
73
+ format * ast.Field
74
+ args * ast.Field
75
+ callers []printfCaller
76
+ failed bool // if true, not a printf wrapper
77
77
}
78
78
79
79
type printfCaller struct {
@@ -168,6 +168,33 @@ func findPrintfLike(pkg *Package) {
168
168
for _ , w := range wrappers {
169
169
// Scan function for calls that could be to other printf-like functions.
170
170
ast .Inspect (w .fn .Body , func (n ast.Node ) bool {
171
+ if w .failed {
172
+ return false
173
+ }
174
+
175
+ // TODO: Relax these checks; issue 26555.
176
+ if assign , ok := n .(* ast.AssignStmt ); ok {
177
+ for _ , lhs := range assign .Lhs {
178
+ if match (lhs , w .format ) || match (lhs , w .args ) {
179
+ // Modifies the format
180
+ // string or args in
181
+ // some way, so not a
182
+ // simple wrapper.
183
+ w .failed = true
184
+ return false
185
+ }
186
+ }
187
+ }
188
+ if un , ok := n .(* ast.UnaryExpr ); ok && un .Op == token .AND {
189
+ if match (un .X , w .format ) || match (un .X , w .args ) {
190
+ // Taking the address of the
191
+ // format string or args,
192
+ // so not a simple wrapper.
193
+ w .failed = true
194
+ return false
195
+ }
196
+ }
197
+
171
198
call , ok := n .(* ast.CallExpr )
172
199
if ! ok || len (call .Args ) == 0 || ! match (call .Args [len (call .Args )- 1 ], w .args ) {
173
200
return true
0 commit comments