@@ -706,12 +706,13 @@ Checking test.c...
706706
707707 <para ><literal >Cppcheck</literal > has internal knowledge about how
708708 standard C/C++ functions work. There is no internal knowledge about how
709- various libraries and environments work. < literal >Cppcheck</ literal > can
710- however be told how libraries and environments work by using configuration
711- files.</para >
709+ all libraries and environments work, and there can't be.
710+ < literal >Cppcheck</ literal > can be told how libraries and environments
711+ work by using configuration files.</para >
712712
713- <para >The idea is that users will be able to download configuration files
714- for all popular libraries and environments here:</para >
713+ <para >The idea is that users will be able to download library
714+ configuration files for all popular libraries and environments
715+ here:</para >
715716
716717 <para ><uri >http://cppcheck.sourceforge.net/archive</uri ></para >
717718
@@ -733,9 +734,10 @@ Checking test.c...
733734 <section >
734735 <title >< alloc> and < dealloc> </title >
735736
736- <para >Allocation and deallocation is defined within
737- <literal >< memory> </literal > or <literal >< resource> using
738- < alloc> and < dealloc> .</literal ></para >
737+ <para >Allocation and deallocation is defined <literal >using
738+ < alloc> and < dealloc> . These are used inside inside
739+ <literal >< memory> </literal > or
740+ <literal >< resource> .</literal ></literal ></para >
739741
740742 <para >Here is example code:</para >
741743
@@ -765,33 +767,23 @@ Checking test.c...</programlisting>
765767 < /memory>
766768< /def> </programlisting >
767769
770+ <para >That tells Cppcheck that <literal >alloc_something</literal >
771+ allocates memory and that the matching deallocation function is
772+ <literal >free_something</literal >.</para >
773+
768774 <para >Output from <literal >Cppcheck</literal >:</para >
769775
770776 <programlisting ># cppcheck --library=something.cfg test.c
771777Checking test.c...
772778[test.c:10]: (error) Memory leak: p</programlisting >
773-
774- <para >Some allocation functions initialize the allocated data. Others
775- don't. Here is a short code example:</para >
776-
777- <programlisting >void f()
778- {
779- char *p = alloc_something();
780- char c = *p;
781- free_something();
782- }</programlisting >
783-
784- <para >If alloc_something() initializes the memory that is allocated then
785- that code is OK. Otherwise that code is bad. To configure that </para >
786-
787- <para />
788779 </section >
789780
790781 <section >
791782 <title >< ignore> and < use> </title >
792783
793- <para >The < ignore> and < use> tells Cppcheck how functions
794- uses allocated memory. Example code:</para >
784+ <para >The <literal >< ignore> </literal > and
785+ <literal >< use> </literal > tells Cppcheck how functions uses
786+ allocated memory. Example code:</para >
795787
796788 <programlisting >void f()
797789{
@@ -840,7 +832,7 @@ Checking test.c...</programlisting>
840832 </section >
841833
842834 <section >
843- <title >< alloc init="false" > </title >
835+ <title >allocate but not initialize </title >
844836
845837 <para >Some allocation function initialize the data, others don't. Here
846838 is a example code:</para >
@@ -852,6 +844,11 @@ Checking test.c...</programlisting>
852844 free_something();
853845}</programlisting >
854846
847+ <para >No error is reported:</para >
848+
849+ <programlisting ># cppcheck --library=something.cfg test.c
850+ Checking test.c...</programlisting >
851+
855852 <para >Here is a configuration that tells cppcheck that alloc_something
856853 doesn't initialize the data:</para >
857854
@@ -865,11 +862,79 @@ Checking test.c...</programlisting>
865862
866863 <para >Now you will get this error message:</para >
867864
868- <programlisting >daniel@dator:~/cppcheck$ ./ cppcheck --library=something.cfg test.c
865+ <programlisting ># cppcheck --library=something.cfg test.c
869866Checking test.c...
870867[test.c:4]: (error) Memory is allocated but not initialized: p</programlisting >
871868 </section >
872869
870+ <section >
871+ <title >function arguments: null pointers</title >
872+
873+ <para >You can define if a function parameter can be NULL or if it must
874+ be non-NULL.</para >
875+
876+ <para >Example code:</para >
877+
878+ <programlisting >void do_something(char *p);
879+
880+ void f()
881+ {
882+ do_something(NULL);
883+ }</programlisting >
884+
885+ <para >Normally no error is reported for that code.</para >
886+
887+ <para >But if the do_something() parameter should be non-NULL you can use
888+ this configuration:</para >
889+
890+ <programlisting >< ?xml version="1.0"?>
891+ < def>
892+ < function name="do_something">
893+ < arg nr="1">
894+ < not-null/>
895+ < /arg>
896+ < /function>
897+ < /def> </programlisting >
898+
899+ <para >Now the output from cppcheck is:</para >
900+
901+ <programlisting ># cppcheck --library=something.cfg test1.c
902+ Checking test1.c...
903+ [test1.c:5]: (error) Null pointer dereference</programlisting >
904+ </section >
905+
906+ <section >
907+ <title >Function arguments: uninitialized data</title >
908+
909+ <para >Here is example code:</para >
910+
911+ <programlisting >void do_something(char *p);
912+
913+ void f()
914+ {
915+ char str[10];
916+ do_something(str);
917+ }</programlisting >
918+
919+ <para >Normally <literal >Cppcheck</literal > doesn't report any error
920+ message for that. However if the parameter must be initialized there is
921+ a problem. Here is a configuration that says that the parameter must be
922+ initialized:</para >
923+
924+ <para ><programlisting >< ?xml version="1.0"?>
925+ < def>
926+ < function name="do_something">
927+ < arg nr="1">
928+ < not-uninit/>
929+ < /arg>
930+ < /function>
931+ < /def> </programlisting >Now the cppcheck output is:</para >
932+
933+ <programlisting ># cppcheck --library=something.cfg test1.c
934+ Checking test1.c...
935+ [test1.c:6]: (error) Uninitialized variable: str</programlisting >
936+ </section >
937+
873938 <section >
874939 <title >no return</title >
875940
0 commit comments