Debian Codegraph @

staticcheck/sa1006/testdata/go1.0/CheckUnsafePrintf/CheckUnsafePrintf.go

raw
1 package pkg
2
3 import (
4 "fmt"
5 "log"
6 "os"
7 "testing"
8 )
9
10 func fn(s string) {
11 fn2 := func() string { return "" }
12 fmt.Printf(fn2()) //@ diag(`should use print-style function`)
13 _ = fmt.Sprintf(fn2()) //@ diag(`should use print-style function`)
14 log.Printf(fn2()) //@ diag(`should use print-style function`)
15 fmt.Printf(s) //@ diag(`should use print-style function`)
16 fmt.Printf(s, "")
17 fmt.Fprintf(os.Stdout, s) //@ diag(`should use print-style function`)
18 fmt.Fprintf(os.Stdout, s, "")
19
20 fmt.Printf(fn2(), "")
21 fmt.Printf("")
22 fmt.Printf("%s", "")
23 fmt.Printf(fn3())
24
25 l := log.New(os.Stdout, "", 0)
26 l.Printf("xx: %q", "yy")
27 l.Printf(s) //@ diag(`should use print-style function`)
28
29 var t testing.T
30 t.Logf(fn2()) //@ diag(`should use print-style function`)
31 t.Errorf(s) //@ diag(`should use print-style function`)
32 t.Fatalf(s) //@ diag(`should use print-style function`)
33 t.Skipf(s) //@ diag(`should use print-style function`)
34
35 var b testing.B
36 b.Logf(fn2()) //@ diag(`should use print-style function`)
37 b.Errorf(s) //@ diag(`should use print-style function`)
38 b.Fatalf(s) //@ diag(`should use print-style function`)
39 b.Skipf(s) //@ diag(`should use print-style function`)
40
41 var tb testing.TB
42 tb.Logf(fn2()) //@ diag(`should use print-style function`)
43 tb.Errorf(s) //@ diag(`should use print-style function`)
44 tb.Fatalf(s) //@ diag(`should use print-style function`)
45 tb.Skipf(s) //@ diag(`should use print-style function`)
46
47 fmt.Errorf(s) //@ diag(`should use print-style function`)
48
49 var nested struct {
50 l log.Logger
51 }
52 nested.l.Printf(s) //@ diag(`should use print-style function`)
53 }
54
55 func fn3() (string, int) { return "", 0 }