2016-04-03 18:11:32 -04:00
|
|
|
# checksrc
|
|
|
|
|
|
|
|
This is the tool we use within the curl project to scan C source code and
|
|
|
|
check that it adheres to our [Source Code Style guide](CODE_STYLE.md).
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
checksrc.pl [options] [file1] [file2] ...
|
|
|
|
|
|
|
|
## Command line options
|
|
|
|
|
2016-04-05 20:00:01 -04:00
|
|
|
`-W[file]` whitelists that file and excludes it from being checked. Helpful
|
|
|
|
when, for example, one of the files is generated.
|
2016-04-04 02:36:21 -04:00
|
|
|
|
|
|
|
`-D[dir]` directory name to prepend to file names when accessing them.
|
|
|
|
|
|
|
|
`-h` shows the help output, that also lists all recognized warnings
|
2016-04-03 18:11:32 -04:00
|
|
|
|
|
|
|
## What does checksrc warn for?
|
|
|
|
|
2016-05-02 05:18:59 -04:00
|
|
|
checksrc does not check and verify the code against the entire style guide,
|
|
|
|
but the script is instead an effort to detect the most common mistakes and
|
2016-11-15 04:47:07 -05:00
|
|
|
syntax mistakes that contributors make before they get accustomed to our code
|
2016-05-02 05:18:59 -04:00
|
|
|
style. Heck, many of us regulars do the mistakes too and this script helps us
|
|
|
|
keep the code in shape.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
|
|
|
checksrc.pl -h
|
|
|
|
|
|
|
|
Lists how to use the script and it lists all existing warnings it has and
|
|
|
|
problems it detects. At the time of this writing, the existing checksrc
|
|
|
|
warnings are:
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `BADCOMMAND`: There's a bad !checksrc! instruction in the code. See the
|
2016-04-03 18:11:32 -04:00
|
|
|
**Ignore certain warnings** section below for details.
|
|
|
|
|
2016-11-15 04:47:07 -05:00
|
|
|
- `BANNEDFUNC`: A banned function was used. The functions sprintf, vsprintf,
|
2016-04-03 18:11:32 -04:00
|
|
|
strcat, strncat, gets are **never** allowed in curl source code.
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `BRACEELSE`: '} else' on the same line. The else is supposed to be on the
|
2016-04-03 18:11:32 -04:00
|
|
|
following line.
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `BRACEPOS`: wrong position for an open brace (`{`).
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `COMMANOSPACE`: a comma without following space
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-05 20:00:01 -04:00
|
|
|
- `COPYRIGHT`: the file is missing a copyright statement!
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `CPPCOMMENTS`: `//` comment detected, that's not C89 compliant
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `FOPENMODE`: `fopen()` needs a macro for the mode string, use it
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `INDENTATION`: detected a wrong start column for code. Note that this warning
|
2016-04-03 18:11:32 -04:00
|
|
|
only checks some specific places and will certainly miss many bad
|
|
|
|
indentations.
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `LONGLINE`: A line is longer than 79 columns.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `PARENBRACE`: `){` was used without sufficient space in between.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `RETURNNOSPACE`: `return` was used without space between the keyword and the
|
2016-04-03 18:11:32 -04:00
|
|
|
following value.
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `SPACEAFTERPAREN`: there was a space after open parenthesis, `( text`.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `SPACEBEFORECLOSE`: there was a space before a close parenthesis, `text )`.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `SPACEBEFORECOMMA`: there was a space before a comma, `one , two`.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `SPACEBEFOREPAREN`: there was a space before an open parenthesis, `if (`,
|
2016-04-03 18:11:32 -04:00
|
|
|
where one was not expected
|
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `SPACESEMILCOLON`: there was a space before semicolon, ` ;`.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `TABS`: TAB characters are not allowed!
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `TRAILINGSPACE`: Trailing white space on the line
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-04-04 02:36:21 -04:00
|
|
|
- `UNUSEDIGNORE`: a checksrc inlined warning ignore was asked for but not used,
|
2016-04-03 18:11:32 -04:00
|
|
|
that's an ignore that should be removed or changed to get used.
|
|
|
|
|
|
|
|
## Ignore certain warnings
|
|
|
|
|
2016-04-05 20:00:01 -04:00
|
|
|
Due to the nature of the source code and the flaws of the checksrc tool, there
|
|
|
|
is sometimes a need to ignore specific warnings. checksrc allows a few
|
|
|
|
different ways to do this.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
|
|
|
### Inline ignore
|
|
|
|
|
|
|
|
You can control what to ignore within a specific source file by providing
|
|
|
|
instructions to checksrc in the source code itself. You need a magic marker
|
|
|
|
that is `!checksrc!` followed by the instruction. The instruction can ask to
|
|
|
|
ignore a specific warning N number of times or you ignore all of them until
|
|
|
|
you mark the end of the ignored section.
|
|
|
|
|
|
|
|
Inline ignores are only done for that single specific source code file.
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
|
|
|
/* !checksrc! disable LONGLINE all */
|
|
|
|
|
2016-04-05 20:00:01 -04:00
|
|
|
This will ignore the warning for overly long lines until it is re-enabled with:
|
2016-04-03 18:11:32 -04:00
|
|
|
|
|
|
|
/* !checksrc! enable LONGLINE */
|
|
|
|
|
2016-04-05 20:00:01 -04:00
|
|
|
If the enabling isn't performed before the end of the file, it will be enabled
|
|
|
|
automatically for the next file.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
|
|
|
You can also opt to ignore just N violations so that if you have a single long
|
|
|
|
line you just can't shorten and is agreed to be fine anyway:
|
|
|
|
|
|
|
|
/* !checksrc! disable LONGLINE 1 */
|
|
|
|
|
|
|
|
... and the warning for long lines will be enabled again automatically after
|
|
|
|
it has ignored that single warning. The number `1` can of course be changed to
|
|
|
|
any other integer number. It can be used to make sure only the exact intended
|
|
|
|
instances are ignored and nothing extra.
|
|
|
|
|
|
|
|
### Directory wide ignore patterns
|
|
|
|
|
2016-05-02 05:18:59 -04:00
|
|
|
This is a method we've transitioned away from. Use inline ignores as far as
|
|
|
|
possible.
|
2016-04-03 18:11:32 -04:00
|
|
|
|
2016-05-02 05:18:59 -04:00
|
|
|
Make a `checksrc.whitelist` file in the directory of the source code with the
|
|
|
|
false positive, and include the full offending line into this file.
|