C++代码静态检车(cppcheck)
安装cppcheck
# root @ ubuntu in ~/xuean_isup on git:master x [10:41:43]
$ apt-cache search cppcheck | grep cppcheck
cppcheck - tool for static C/C++ code analysis (CLI)
cppcheck-gui - tool for static C/C++ code analysis (GUI)
# root @ ubuntu in ~/xuean_isup on git:master x [10:40:05] C:127
$ apt install -y cppcheck
使用
#!/bin/bash
scriptPath=$(cd $(dirname $0) && pwd)
cd ${scriptPath}
mkdir cppcheck
rm ./cppcheck/cppcheck.log
# cppcheck --enable=warning --inconclusive --force --std=posix -i src/ISUP_libs -I include/x64 src
cppcheck --enable=warning --inconclusive --force --std=posix -i src/ISUP_libs -I include/x64 src 2>cppcheck/cppcheck.log
# cppcheck --enable=all --inconclusive --force --std=posix -i src/ISUP_libs -I include/x64 src 2>cppcheck/cppcheck.log
# cppcheck --quiet --enable=all --inconclusive --force --std=posix -i src/ISUP_libs -I include/x64 src 2>cppcheck.log
cd cppcheck
rm cppcheck.*.log
grep -F "error" cppcheck.log >cppcheck.error.log
grep -F "warning" cppcheck.log >cppcheck.warning.log
grep -F "style" cppcheck.log >cppcheck.style.log
grep -F "performance" cppcheck.log >cppcheck.performance.log
grep -F "inconclusive" cppcheck.log >cppcheck.inconclusive.log
grep -F "portability" cppcheck.log >cppcheck.portability.log
grep -F "information" cppcheck.log >cppcheck.information.log
grep -F "unusedFunction" cppcheck.log >cppcheck.unusedFunction.log
grep -F "missingInclude" cppcheck.log >cppcheck.missingInclude.log
cat cppcheck.error.log | grep error
cat cppcheck.warning.log | grep -v -F ".h:" | grep -v -F "scanf without field width limits can crash with huge input data" | grep -v -F "NextPack" | grep warning