|
|
# Static Code Analysis using `Cppcheck`
|
|
|
|
|
|
You can run a static code analysis to detect memory-leaks, unitialized variable, practices which vioaltes safety standards, ...
|
|
|
We use [cppchecker](https://en.wikipedia.org/wiki/Cppcheck).
|
|
|
You also need the `cppcheck-htmlreport` which is provided by the apt-get resources of the `cppcheck` package.
|
|
|
`CMake` should automatically find the tools if available and activate targets for generating html report from the code analysis
|
|
|
|
|
|
![Auswahl_002](/uploads/824fad4f46172e2226dc8852b70d0623/Auswahl_002.png)
|
|
|
|
|
|
**Please make sure when executing these targets that your shell supports pipe redirection to `stderr`, e.g. `2>`.
|
|
|
`zshell` does this not correct.**
|
|
|
|
|
|
|
|
|
# Static Code Analysis using `Clang`
|
|
|
|
|
|
Our `CMake` setup does not provide any special targets for static code analysis using `Clang`.
|
|
|
You can do this manually and creating reports by using
|
|
|
|
|
|
```bash
|
|
|
export CCC_CC=clang CCC_CXX=clang++ ;
|
|
|
cmake ../cmess -DCMAKE_CXX_COMPILER=/usr/share/clang/scan-build-3.6/c++-analyzer -DCMAKE_C_COMPILER=/usr/share/clang/scan-build-3.6/ccc-analyzer -DDEBUG=ON
|
|
|
scan-build -analyze-headers -maxloop 500 -stats make
|
|
|
|
|
|
# for newer versions
|
|
|
export CCC_CC=clang CCC_CXX=clang++ ;
|
|
|
cmake ../cmess -DCMAKE_CXX_COMPILER=/usr/share/clang/scan-build-3.8/libexec/c++-analyzer -DCMAKE_C_COMPILER=/usr/share/clang/scan-build-3.8/libexec/ccc-analyzer -DDEBUG=ON
|
|
|
scan-build -analyze-headers -maxloop 500 -stats make
|
|
|
```
|
|
|
|