Writing rules: use 'cppcheck --rule=.+' instead of 'cppcheck --debug' to see simplified code
This commit is contained in:
parent
68f2c47c5c
commit
ac60a41a7e
|
@ -140,24 +140,19 @@
|
|||
free(p);
|
||||
}</programlisting>
|
||||
|
||||
<para>To see the simplified code use <literal>cppcheck --debug
|
||||
dealloc.cpp</literal>.</para>
|
||||
<para>To see the simplified code you can use <literal>cppcheck
|
||||
--rule=".+" dealloc.cpp</literal>:</para>
|
||||
|
||||
<programlisting>##file dealloc.cpp
|
||||
1: void f ( ) {
|
||||
2: if ( p ) {
|
||||
3: free ( p ) ; }
|
||||
4: }</programlisting>
|
||||
<programlisting>$ ./cppcheck --rule=".+" dealloc.cpp
|
||||
Checking dealloc.cpp...
|
||||
[dealloc.cpp:1]: (style) found ' void f ( ) { if ( p ) { free ( p ) ; } }'</programlisting>
|
||||
|
||||
<para>In the <literal>--debug</literal> output there are line feeds and
|
||||
line numbers. But the newlines and line numbers are only there to make
|
||||
the output easier to read. The real simplified code is written on a
|
||||
single line:</para>
|
||||
<para>In short, the simplified code is:</para>
|
||||
|
||||
<programlisting> void f ( ) { if ( p ) { free ( p ) ; } }</programlisting>
|
||||
|
||||
<para>Now we can use <literal>cppcheck --rule</literal> to develop a
|
||||
regular expression.</para>
|
||||
<para>Now that the simplified code is known we can create a regular
|
||||
expression:</para>
|
||||
|
||||
<programlisting>$ cppcheck --rule="if \( p \) { free \( p \) ; }" dealloc.cpp
|
||||
Checking dealloc.cpp...
|
||||
|
|
Loading…
Reference in New Issue