Cppcheck reports

From The Document Foundation Wiki
Jump to: navigation, search

This page documents how to generate cppcheck reports in the form of a browseable tree of sources files.

What's cppcheck

Cppcheck is an open source static code analyzer tool for C/C++ programming languages. So its goal is to detect some bugs (other than syntax errors).

Example results

Example generated results can be found here:



Retrieve LibreOffice sources

Retrieve LibreOffice sources in a <LO sources> directory with this command:

$ git clone git://anongit.freedesktop.org/libreoffice/core libo

(see Development/Native Build for more details)

Retrieve and build cppcheck sources

You can install cppcheck from distribution packages but it's better to retrieve last sources with git since there are improvements everyday. So choose and go into <cppcheck directory> then run these commands to retrieve sources and build cppcheck:

$ git clone git://github.com/danmar/cppcheck.git
$ cd cppcheck
$ make

On i5 with 6Gb, Building takes less than a minute.

Generate reports

To summarize, you've got to generate an xml file containing all the warnings/errors detected by cppcheck. Then you must launch a script to generate a browseable tree from the xml file + LibreOffice sources. Cppcheck allows a lot of options but here are some simple steps: - go to <LO sources> directory - create a file named "cppcheck_supp.txt" which contains only unusedFunction - run this command to launch cppcheck detection:

$ <cppcheck directory>/cppcheck  -i external/ -i workdir/ --xml --suppressions-list=cppcheck_supp.txt --enable=all --max-configs=25 ./ 2> ./err.xml

(-i option allows to remove some directories to check, --suppressions-list allows to disable some types of detection, --enable=all allows to detect every types of detections, removing it allows to have only errors) Notice that on i5 with 6Gb, it takes several hours to have the result - run this command to generate the browseable tree:

$ <cppcheck directory>/htmlreport/cppcheck-htmlreport  --file=err.xml --title=LibreOffice --report-dir=cppcheck_reports --source-dir=.

You'll get a new directory called cppcheck_reports in your LO sources. The main page to browse in it is index.html With the configuration mentioned above, this part takes only some minutes.