manual: updated documentation for --template and --template-location
This commit is contained in:
parent
92fd0595b1
commit
74b1d1deb6
|
@ -5,7 +5,7 @@
|
||||||
<bookinfo>
|
<bookinfo>
|
||||||
<title>Cppcheck 1.84 dev</title>
|
<title>Cppcheck 1.84 dev</title>
|
||||||
|
|
||||||
<date>2018-01-21</date>
|
<date>2018-04-23</date>
|
||||||
</bookinfo>
|
</bookinfo>
|
||||||
|
|
||||||
<chapter>
|
<chapter>
|
||||||
|
@ -661,93 +661,287 @@ cppcheck -DA --force file.c</programlisting>
|
||||||
<para>If you want to reformat the output so it looks different you can use
|
<para>If you want to reformat the output so it looks different you can use
|
||||||
templates.</para>
|
templates.</para>
|
||||||
|
|
||||||
<para>To get Visual Studio compatible output you can use <parameter
|
<section>
|
||||||
class="command">--template=vs</parameter>:</para>
|
<title>Predefined output formats</title>
|
||||||
|
|
||||||
<programlisting>cppcheck --template=vs gui/test.cpp</programlisting>
|
<para>To get Visual Studio compatible output you can use <parameter
|
||||||
|
class="command">--template=vs</parameter>:</para>
|
||||||
|
|
||||||
<para>This output will look like this:</para>
|
<programlisting>cppcheck --template=vs samples/arrayIndexOutOfBounds/bad.c</programlisting>
|
||||||
|
|
||||||
<programlisting>Checking gui/test.cpp...
|
<para>This output will look like this:</para>
|
||||||
gui/test.cpp(31): error: Memory leak: b
|
|
||||||
gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting>
|
|
||||||
|
|
||||||
<para>To get gcc compatible output you can use <parameter
|
<programlisting>Checking samples/arrayIndexOutOfBounds/bad.c ...
|
||||||
class="command">--template=gcc</parameter>:</para>
|
samples/arrayIndexOutOfBounds/bad.c(6): error: Array 'a[2]' accessed at index 2, which is out of bounds.</programlisting>
|
||||||
|
|
||||||
<programlisting>cppcheck --template=gcc gui/test.cpp</programlisting>
|
<para>To get <literal>gcc</literal> compatible output you can use
|
||||||
|
<parameter class="command">--template=gcc</parameter>:</para>
|
||||||
|
|
||||||
<para>The output will look like this:</para>
|
<programlisting>cppcheck --template=gcc samples/arrayIndexOutOfBounds/bad.c</programlisting>
|
||||||
|
|
||||||
<programlisting>Checking gui/test.cpp...
|
<para>The output will look like this:</para>
|
||||||
gui/test.cpp:31: error: Memory leak: b
|
|
||||||
gui/test.cpp:16: error: Mismatching allocation and deallocation: k</programlisting>
|
|
||||||
|
|
||||||
<para>You can write your own pattern (for example a comma-separated
|
<programlisting>Checking samples/arrayIndexOutOfBounds/bad.c ...
|
||||||
format):</para>
|
samples/arrayIndexOutOfBounds/bad.c:6:6: warning: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
|
||||||
|
a[2] = 0;
|
||||||
|
^</programlisting>
|
||||||
|
</section>
|
||||||
|
|
||||||
<programlisting>cppcheck --template="{file},{line},{severity},{id},{message}" gui/test.cpp</programlisting>
|
<section>
|
||||||
|
<title>User defined output format (single line)</title>
|
||||||
|
|
||||||
<para>The output will look like this:</para>
|
<para>You can write your own pattern. For instance, to get warning
|
||||||
|
messages that are formatted like old <literal>gcc</literal> such format
|
||||||
|
can be used:</para>
|
||||||
|
|
||||||
<programlisting>Checking gui/test.cpp...
|
<programlisting>cppcheck --template="{file}:{line}: {severity}: {message}" samples/arrayIndexOutOfBounds/bad.c</programlisting>
|
||||||
gui/test.cpp,31,error,memleak,Memory leak: b
|
|
||||||
gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocation: k</programlisting>
|
|
||||||
|
|
||||||
<para>The following format specifiers are supported:</para>
|
<para>The output will look like this:</para>
|
||||||
|
|
||||||
<variablelist>
|
<programlisting>Checking samples/arrayIndexOutOfBounds/bad.c ...
|
||||||
<varlistentry>
|
samples/arrayIndexOutOfBounds/bad.c:6: error: Array 'a[2]' accessed at index 2, which is out of bounds.</programlisting>
|
||||||
<term>callstack</term>
|
|
||||||
|
|
||||||
<listitem>
|
<para>A comma separated format:</para>
|
||||||
<para>callstack - if available</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<programlisting>cppcheck --template="{file},{line},{severity},{id},{message}" samples/arrayIndexOutOfBounds/bad.c</programlisting>
|
||||||
<term>file</term>
|
|
||||||
|
|
||||||
<listitem>
|
<para>The output will look like this:</para>
|
||||||
<para>filename</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<programlisting>Checking samples/arrayIndexOutOfBounds/bad.c ...
|
||||||
<term>id</term>
|
samples/arrayIndexOutOfBounds/bad.c,6,error,arrayIndexOutOfBounds,Array 'a[2]' accessed at index 2, which is out of bounds.</programlisting>
|
||||||
|
</section>
|
||||||
|
|
||||||
<listitem>
|
<section>
|
||||||
<para>message id</para>
|
<title>User defined output format (multi line)</title>
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<para>Many warnings have multiple locations. Example code:</para>
|
||||||
<term>line</term>
|
|
||||||
|
|
||||||
<listitem>
|
<programlisting>void f(int *p)
|
||||||
<para>line number</para>
|
{
|
||||||
</listitem>
|
*p = 3; // line 3
|
||||||
</varlistentry>
|
}
|
||||||
|
|
||||||
<varlistentry>
|
int main()
|
||||||
<term>message</term>
|
{
|
||||||
|
int *p = 0; // line 8
|
||||||
|
f(p); // line 9
|
||||||
|
return 0;
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
<listitem>
|
<para>There is a possible null pointer dereference at line 3. Cppcheck
|
||||||
<para>verbose message text</para>
|
can show how it came to that conclusion by showing extra location
|
||||||
</listitem>
|
information. You need to use both <literal>--template</literal> and
|
||||||
</varlistentry>
|
<literal>--template-location</literal> at the command line.</para>
|
||||||
|
|
||||||
<varlistentry>
|
<para>Example command:</para>
|
||||||
<term>severity</term>
|
|
||||||
|
|
||||||
<listitem>
|
<programlisting>cppcheck --template="{file}:{line}: {severity}: {message}\n{code}" --template-location="{file}:{line}: note: {info}\n{code}" multiline.c</programlisting>
|
||||||
<para>a type/rank of message</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
<para>The escape sequences \b (backspace), \n (newline), \r (formfeed) and
|
<para>The output from Cppcheck is:</para>
|
||||||
\t (horizontal tab) are supported.</para>
|
|
||||||
|
<programlisting>Checking multiline.c ...
|
||||||
|
multiline.c:3: warning: Possible null pointer dereference: p
|
||||||
|
*p = 3;
|
||||||
|
^
|
||||||
|
multiline.c:8: note: Assignment 'p=0', assigned value is 0
|
||||||
|
int *p = 0;
|
||||||
|
^
|
||||||
|
multiline.c:9: note: Calling function 'f', 1st argument 'p' value is 0
|
||||||
|
f(p);
|
||||||
|
^
|
||||||
|
multiline.c:3: note: Null pointer dereference
|
||||||
|
*p = 3;
|
||||||
|
^</programlisting>
|
||||||
|
|
||||||
|
<para>The first line in the warning is formatted by the
|
||||||
|
<literal>--template</literal> format.</para>
|
||||||
|
|
||||||
|
<para>The other lines in the warning are formatted by the
|
||||||
|
<literal>--template-location</literal> format.</para>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Format specifiers for --template</title>
|
||||||
|
|
||||||
|
<para>The available specifiers for <literal>--template</literal>
|
||||||
|
are:</para>
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term>{file}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>File name</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{line}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Line number</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{column}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Column number</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{callstack}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Write all locations. Each location is written in
|
||||||
|
[{file}:{line}] format and the locations are separated by ->.
|
||||||
|
For instance it might look like: [multiline.c:8] ->
|
||||||
|
[multiline.c:9] -> [multiline.c:3]</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{inconclusive:text}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>If warning is inconclusive then the given text is written.
|
||||||
|
The given text can be any arbitrary text that does not contain }.
|
||||||
|
Example: {inconclusive:inconclusive,}</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{severity}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>error/warning/style/performance/portability/information</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{message}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>The warning message</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{id}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Warning id</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{code}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>The real code.</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\t</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Tab</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\t</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Newline</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\r</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Carriage return</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Format specifiers for --template-location</title>
|
||||||
|
|
||||||
|
<para>The available specifiers for
|
||||||
|
<literal>--template-location</literal> are:</para>
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term>{file}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>File name</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{line}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Line number</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{column}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Column number</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{info}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Information message about current location</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>{code}</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>The real code.</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\t</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Tab</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\t</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Newline</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>\r</term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>Carriage return</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
</section>
|
||||||
</chapter>
|
</chapter>
|
||||||
|
|
||||||
<chapter>
|
<chapter>
|
||||||
|
@ -927,8 +1121,8 @@ Checking test.c...
|
||||||
|
|
||||||
<programlisting>// cppcheck-suppress arrayIndexOutOfBounds symbolName=arr</programlisting>
|
<programlisting>// cppcheck-suppress arrayIndexOutOfBounds symbolName=arr</programlisting>
|
||||||
|
|
||||||
<para> You can write comments for the suppress, however is recommended
|
<para>You can write comments for the suppress, however is recommended to
|
||||||
to use ; or // to specify where they start:</para>
|
use ; or // to specify where they start:</para>
|
||||||
|
|
||||||
<programlisting>// cppcheck-suppress arrayIndexOutOfBounds ; some comment
|
<programlisting>// cppcheck-suppress arrayIndexOutOfBounds ; some comment
|
||||||
// cppcheck-suppress arrayIndexOutOfBounds // some comment</programlisting>
|
// cppcheck-suppress arrayIndexOutOfBounds // some comment</programlisting>
|
||||||
|
|
Loading…
Reference in New Issue