mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix printf violations inside of the gvisor code
Recently printf.Analyzer has become stricter (https://github.com/golang/go/issues/60529) which led to new findings. gvisor nogo tests run this analyzer and fail if it produces findings. PiperOrigin-RevId: 671657227
This commit is contained in:
@@ -56,7 +56,7 @@ 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
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (r *CgroupsResult) AsError() error {
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+2
-2
@@ -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")
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user