Skip to content

Latest commit

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Variable Format

variable-format is a go/analysis-based tool that identifies non-constant strings used as the format parameter to a printf-like function. There are legitimate use cases for this, so seeing this does not inherently mean you have bad code.

However, if you're trying to track down in a large codebase where %!x(MISSING) is coming from, this analyzer can help you find it. esults are flaws.

CI

Example messages

Given the following source code example.go:

1package example
23import (
4"fmt"5"os"6	)
78funcmain() {
9fmt.Printf(os.Args[0], "Usage", "...")
10	}

variable-format will report the following:

$t variable-format ./....../example.go:9:13: variable `os.Args[0]` used for fmt.Printf format parameterexit status 3

Usage

Run from source with go run github.com/mutility/variable-format@latest or install with go install github.com/mutility/variable-format@latest and run variable-format from GOPATH/bin.

You can configure behvior at the command line by passing the flags below, or in library use by setting fields on varfmt.Analyzer().

FlagFieldMeaning
-no-argsSuppressNoArgsSuppress reports of variable formats with no subsequent arguments
-funcssee printf.AnalyzerTreat additional functions as printf-like

Bug reports and feature contributions

variable-format is developed in spare time, so while bug reports and feature contributions are welcomed, it may take a while for them to be reviewed. If possible, try to find a minimal reproduction before reporting a bug. Bugs that are difficult or impossible to reproduce will likely be closed.

All bug fixes will include tests to help ensure no regression; correspondingly all contributions should include such tests.

Mutility Analyzers

variable-format is part of mutility-analyzers.

About

Find variable strings used as Printf-like format strings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages