Skip to content

Commit

Permalink
Fix printf violations inside of the gvisor code
Browse files Browse the repository at this point in the history
Recently printf.Analyzer has become stricter
(golang/go#60529)
which led to new findings.
gvisor nogo tests run this analyzer and fail if it produces findings.

PiperOrigin-RevId: 671657227
  • Loading branch information
gvisor-bot committed Sep 6, 2024
1 parent 40bde6c commit 3c4b246
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/sentry/control/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ type CgroupsResult struct {
// AsError interprets the result as an error.
func (r *CgroupsResult) AsError() error {
if r.IsError {
return fmt.Errorf(r.Data)
return fmt.Errorf("%s", r.Data)
}
return nil
}

// Unpack splits CgroupsResult into a (value, error) tuple.
func (r *CgroupsResult) Unpack() (string, error) {
if r.IsError {
return "", fmt.Errorf(r.Data)
return "", fmt.Errorf("%s", r.Data)
}
return r.Data, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/tcpip/nftables/nftinterp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func checkOp(t *testing.T, test interpretOperationTestAction, checkFunc func(str
t.Fatalf("expected non-nil operation for %s, got nil", test.tname)
}
if err := checkFunc(test.tname, test.expected, actual); err != nil {
t.Fatalf(err.Error())
t.Fatalf("%s", err.Error())
}
}

Expand Down Expand Up @@ -815,11 +815,11 @@ func TestInterpretRule(t *testing.T) {
switch testOp.(type) {
case *immediate:
if err := checkImmediateOp(test.tname, testOp, op); err != nil {
t.Fatalf(err.Error())
t.Fatalf("%s", err.Error())
}
case *comparison:
if err := checkComparisonOp(test.tname, testOp, op); err != nil {
t.Fatalf(err.Error())
t.Fatalf("%s", err.Error())
}
// TODO(b/345684870): cases will be added here as more types are supported.
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/dockerutil/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestProfile(t *testing.T) {

// Check all expected files exist and have data.
if err := checkFiles(localProfile.BasePath, tc.expectedFiles); err != nil {
t.Fatalf(err.Error())
t.Fatalf("%s", err.Error())
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion runsc/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Main() {
// Create a new Config from the flags.
conf, err := config.NewFromFlags(flag.CommandLine)
if err != nil {
util.Fatalf(err.Error())
util.Fatalf("%s", err.Error())
}

var errorLogger io.Writer
Expand Down
4 changes: 2 additions & 2 deletions runsc/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (d *Debug) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomm
}

if err := c.Sandbox.ChangeLogging(args); err != nil {
return util.Errorf(err.Error())
return util.Errorf("%s", err.Error())
}
util.Infof("Logging options changed")
}
Expand All @@ -235,7 +235,7 @@ func (d *Debug) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomm
src := opts[1]
dest := opts[2]
if err := c.Sandbox.Mount(c.ID, fstype, src, dest); err != nil {
util.Fatalf(err.Error())
util.Fatalf("%s", err.Error())
}
}

Expand Down
2 changes: 1 addition & 1 deletion runsc/cmd/metricserver/metricserver_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type cmd struct {
func (c *cmd) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus {
conf, err := config.NewFromFlags(flag.CommandLine)
if err != nil {
util.Fatalf(err.Error())
util.Fatalf("%s", err.Error())
}
if conf.MetricServer == "" || conf.RootDir == "" {
flag.CommandLine.Usage()
Expand Down
2 changes: 1 addition & 1 deletion runsc/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ func (c *Container) Destroy() error {
if len(errs) == 0 {
return nil
}
return fmt.Errorf(strings.Join(errs, "\n"))
return fmt.Errorf("%s", strings.Join(errs, "\n"))
}

func (c *Container) sandboxID() string {
Expand Down
2 changes: 1 addition & 1 deletion runsc/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ func checkBinaryPermissions(conf *config.Config) error {
}

if info.Mode().Perm()&neededBits != neededBits {
return fmt.Errorf(specutils.FaqErrorMsg("runsc-perms", fmt.Sprintf("%s does not have the correct permissions", exePath)))
return fmt.Errorf("%s", specutils.FaqErrorMsg("runsc-perms", fmt.Sprintf("%s does not have the correct permissions", exePath)))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tools/checkaligned/checkaligned.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func run(pass *analysis.Pass) (any, error) {
}
typeNameLen += 2 // Account for the "32" or "64" suffix.
typeName := blocked[len(blocked)-typeNameLen:]
pass.Reportf(selExpr.Pos(), fmt.Sprintf("don't call atomic.%s; use atomicbitops.%s instead", blocked, typeName))
pass.Reportf(selExpr.Pos(), "%s", fmt.Sprintf("don't call atomic.%s; use atomicbitops.%s instead", blocked, typeName))
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/checkescape/checkescape.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (es *Escapes) Reportf(pass *analysis.Pass) {
fmt.Fprintf(&b, "→ %s ", cs.Resolved.String())
}
fmt.Fprintf(&b, "→ %s", es.Details[r])
pass.Reportf(es.CallSites[r][0].LocalPos, b.String())
pass.Reportf(es.CallSites[r][0].LocalPos, "%s", b.String())
}
}

Expand Down Expand Up @@ -930,7 +930,7 @@ func run(pass *analysis.Pass, binary io.Reader) (any, error) {
}
for reason, local := range testReasons {
// We didn't find the escapes we wanted.
pass.Reportf(fdecl.Pos(), fmt.Sprintf("testescapes not found: reason=%s, local=%t", reason, local))
pass.Reportf(fdecl.Pos(), "%s", fmt.Sprintf("testescapes not found: reason=%s, local=%t", reason, local))
}
if len(testReasons) > 0 {
// Report for debugging.
Expand Down
2 changes: 1 addition & 1 deletion tools/checkunsafe/check_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func run(pass *analysis.Pass) (any, error) {
}

// Throw the error.
pass.Reportf(imp.Pos(), fmt.Sprintf("package unsafe imported by %s; must end with _unsafe.go", path.Base(filename)))
pass.Reportf(imp.Pos(), "%s", fmt.Sprintf("package unsafe imported by %s; must end with _unsafe.go", path.Base(filename)))
}
}
return nil, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (g *interfaceGenerator) validatePrimitiveNewtype(t *ast.Ident) {
case "string":
g.abortAt(t.Pos(), "Type 'string' is dynamically-sized and cannot be marshalled, use a fixed size byte array '[...]byte' instead")
default:
debugfAt(g.f.Position(t.Pos()), fmt.Sprintf("Found derived type '%s', will attempt dispatch via marshal.Marshallable.\n", t.Name))
debugfAt(g.f.Position(t.Pos()), "%s", fmt.Sprintf("Found derived type '%s', will attempt dispatch via marshal.Marshallable.\n", t.Name))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/go_marshal/gomarshal/generator_interfaces_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (g *interfaceGenerator) isStructPacked(st *ast.StructType) bool {
if f.Tag.Value == "`marshal:\"unaligned\"`" {
if packed {
debugfAt(g.f.Position(g.t.Pos()),
fmt.Sprintf("Marking type '%s' as not packed due to tag `marshal:\"unaligned\"`.\n", g.t.Name))
"%s", fmt.Sprintf("Marking type '%s' as not packed due to tag `marshal:\"unaligned\"`.\n", g.t.Name))
packed = false
}
}
Expand Down

0 comments on commit 3c4b246

Please sign in to comment.