Writing rules: use 'cppcheck --rule=.+' instead of 'cppcheck --debug' to see simplified code

This commit is contained in:
Daniel Marjamäki 2010-12-05 14:08:49 +01:00
parent 68f2c47c5c
commit ac60a41a7e
1 changed files with 9 additions and 14 deletions

View File

@ -140,24 +140,19 @@
free(p); free(p);
}</programlisting> }</programlisting>
<para>To see the simplified code use <literal>cppcheck --debug <para>To see the simplified code you can use <literal>cppcheck
dealloc.cpp</literal>.</para> --rule=".+" dealloc.cpp</literal>:</para>
<programlisting>##file dealloc.cpp <programlisting>$ ./cppcheck --rule=".+" dealloc.cpp
1: void f ( ) { Checking dealloc.cpp...
2: if ( p ) { [dealloc.cpp:1]: (style) found ' void f ( ) { if ( p ) { free ( p ) ; } }'</programlisting>
3: free ( p ) ; }
4: }</programlisting>
<para>In the <literal>--debug</literal> output there are line feeds and <para>In short, the simplified code is:</para>
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>
<programlisting> void f ( ) { if ( p ) { free ( p ) ; } }</programlisting> <programlisting> void f ( ) { if ( p ) { free ( p ) ; } }</programlisting>
<para>Now we can use <literal>cppcheck --rule</literal> to develop a <para>Now that the simplified code is known we can create a regular
regular expression.</para> expression:</para>
<programlisting>$ cppcheck --rule="if \( p \) { free \( p \) ; }" dealloc.cpp <programlisting>$ cppcheck --rule="if \( p \) { free \( p \) ; }" dealloc.cpp
Checking dealloc.cpp... Checking dealloc.cpp...