C + + code static analysis tool Cppcheck
Author:echo Chen (Chenbin)
Email:[email protected]
blog:blog.csdn.net/chen19870707
date:jan.1st, 2015
Recent games into the tail, has been on-line operation, the demand is relatively small, can have time to organize the optimization of the code, but the optimization without a standard, it is difficult to have a practical effect, so first from the simple code static analysis began to find a lot of code static check tools, Splint,pclint, purify, Infusion, Cppcheck and so on, but Cppcheck document the most streamlined, looks the most easy to use, personal simple ideas to solve complex problems, so chose Cppcheck.
1.cppcheck Downloads
Cppcheck now has a version of 1.68, the new version of Cppcheck needs c++11 support, here to choose the most classic version 49.
: cppcheck-1.49.tar.bz2
2.cppcheck Installation
1: tar jxvf cppcheck-1.49.tar.gz
2: CD cppcheck-1.49
3: make
4: make install
If the make process reports the following error:
You need to install the Pcre third party expression Library
After installation, make & make install succeeded.
3.cppcheck use
Use Cppcheck–h to see Help, here are a few of the most useful options
1: cppcheck.-j 3--enable=all--xml 2>result.xml
The-J parameter specifies the number of threads to check, and the-j parameter is useful if you need to check the amount of code.
--ENABLE Specifies the currently specified check level, optional parameters are all,style,information, etc.
--xml is the version of the output XML
4.cppcheck Analysis ResultsSome of the results of the project are captured as follows:
The main point here is that these variables should be set to the const variable.
5.cppcheck can parse the type of error 1: automatic variable checking
2: bounds checking of arrays
3: class Check
4: expired function, obsolete function call check
5: Abnormal memory usage, release check
6: memory leak check, mainly through memory reference pointers
7: OS resource release check, interrupt, file descriptor, etc.
8: exception STL function Use check
9: code format error, and performance factor check
-
Echo chen:blog.csdn.net/chen19870707
-
C + + code static analysis tool Cppcheck