C/C++代碼靜態檢查工具Cppcheck在VS2008開發環境中的安裝配置和使用
Cppcheck is an analysis tool for C/C++code. Unlike C/C++ compilers and many other analysis tools, it doesn’t detect syntax errors. Cppcheck only detects the types of bugs that the compilers normally fail to detect. The goal is no false positives.
Cppcheck is rarely wrong about reported errors. But there are many bugs that it doesn’t detect.
它可以檢查不通過編譯的文件。
執行的檢查包括:
(1)、自動變量檢查;(2)、數組的邊界檢查;(3)、class類檢查;(4)、過期的函數,廢棄函數調用檢查;(5)、異常內存使用,釋放檢查;(6)、內存泄漏檢查,主要是通過內存引用指針;(7)、操作系統資源釋放檢查,中斷,文件描述符等;(8)、異常STL 函數使用檢查;(9)、代碼格式錯誤,以及性能因素檢查。
安裝步驟:
(1)、從http://sourceforge.net/projects/cppcheck/下載最新版本cppcheck-1.58-x86-Setup.msi,將其安裝到D:\ProgramFiles\Cppcheck路徑下(注意:不要包含中文路徑,也可以從https://github.com/danmar/cppcheck/ 下載源代碼);
(2)、打開vs2008,Tools-->ExternalTools-->點擊Add,Title:Cppcheck;Command:D:\ProgramFiles\Cppcheck\cppcheck.exe;Argments:--quiet --verbose --template=vs$(ItemPath);Initial directory:$(ItemDir);選中Use Output window;點擊OK.
例如,在F:\test\Cppcheck文件夾下創建了一個Cppcheck工程,F:\test\Cppcheck\Cppcheck文件夾下存放著一些.cpp文件: