English | 中文文档
cppdector受到TscanCode的启发。在使用TscanCode的过程中,发现TscanCode缺少部分团队需要的检测项,如:
cppdetector吸收了TscanCode中的一些规则,并增加了实际开发中得到验证的原则(非线程安全的单例模式检测), 谷歌c++风格,effectvie C++等编程规范,帮助程序员从一开始就发现代码缺陷,提高代码质量。
cppdetector通过正则和字符串匹配检测代码。在检测时,不需要编译被检测代码。
任何 支持C++17(filesystem)的 编译器都可以工作。
可选择的编译器:
- Visual Studio 2017 version 15.7(or above)
- Linux:GCC 8.0(or later)
- Mac:clang 7.0(or later)
cppdetector采用cmake进行工程配置
//cd到cppdetector目录
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
//you can Open the cppdetector.sln to compile in the Build directory
- clion打开cppdetector根目录
- Visual Studio->“打开本地文件夹”,选中cppdetector根目录
cd buildscript
buildwithcmd.bat
//cd到cppdetector目录
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
#you can build with multi-core, eg: 6 core
#cmake --build . --config RelWithDebInfo -j6
#you can compile with `make` on Linux and Mac
#make
####I DE打开cmake项目
- clion打开cppdetector根目录
cppdetector multithread "codepath"
./cppdetector multithread /Users/hualongzhang/work/cppdetector/detector_core
Parameter | Description |
---|---|
Param1 | singlethread, multithread or multiprocess |
Param2 | 代码路径 |
Param3 | 例外配置文件路径 |
Param4 | 规则名配置文件路径 |
Param5 | 结果存放路径 |
[
"/Users/hualongzhang/work/cppdetector/detector_core/3rdparty",
"/Users/hualongzhang/work/cppdetector/detector_core/common/codeconversion.h"
]
可由代码生成:DetectorCommon().setDetectorRuleNames((resultDir / "detectorRuleNames.json").string()
数组规则名如下:
{
"ArrayDetector": [
"ArrayRuleIndexOutOfBounds",
"ArrayRuleIndexUsedBeforeCheck",
"ArrayRuleIndexCheckDefectively",
"ArrayRuleBufferOverflow",
"ArrayRuleIndexOutOfBoundsFromFunc",
"ArrayRuleIndexOutOfBoundsInLoop",
"ArrayRuleMemsetZeroByte"
]
}
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core"
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core" "/Users/hualongzhang/work/cppdetector"
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core" "/Users/hualongzhang/work/cppdetector" "/Users/hualongzhang/work/cppdetector/supporting/exceptionconfig.json"
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core" "/Users/hualongzhang/work/cppdetector" "/Users/hualongzhang/work/cppdetector/supporting/exceptionconfig.json"
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core" "/Users/hualongzhang/work/cppdetector" "/Users/hualongzhang/work/cppdetector/supporting/exceptionconfig.json"
"/Users/hualongzhang/work/cppdetector/supporting/detectorRuleNames.json"
./cppdetector multithread "/Users/hualongzhang/work/cppdetector/detector_core" "/Users/hualongzhang/work/cppdetector" "/Users/hualongzhang/work/cppdetector/supporting/exceptionconfig.json"
"/Users/hualongzhang/work/cppdetector/supporting/detectorRuleNames.json" /Users/hualongzhang/work/cppdetector/bin/detectorResult
运行脚本进行测试,你也可以更改run.bat中的代码路径来检测其他代码
cd cppdetector\release\windows_x64
run.bat
github: zhlongfj
email: [email protected]