Guidelines and HOWTOs/Code Checking

From KDE Community Wiki

Code Checking

There are a lot of ways to find bugs in KDE code. Increasingly, KDE developers have started to use automated tools. You can use some of those tools to improve your own code.

The KDE 'Krazy' Checker

KDE developers have a simple set of tests that are collectively known as "Krazy". These tests were originally developed to be run as part of a larger set of tests on a machine known as http://www.englishbreakfastnetwork.org, or EBN for short.

Suppressing false-positives

The Krazy tests are designed to minimise false positives (that is, alerts that do not represent real problems). However because most of the tests are conducted on a single line, there are some tests that might produce such a false positive. For example, code that does something like: QString mystring; mystring += "/"; will be flagged by the doublequote_chars checker, because it is more efficient to add a single char, as shown below: QString mystring; // note that we are using single quotes - this is a char, not a char array mystring += '/';

That same checker will produce a false positive for code that looks like: std::string mystring; mystring += "/";

You can suppress these false positives using a special comment format. To exclude a particular plugin from being run on a line of code, simply add a C++ comment containing the string "krazy:exclude=<plugin_name>".

Specifically, for this plugin use "krazy:exclude=doublequote_chars". For example:

  lenstr = "0" + lenstr;

becomes

  lenstr = "0" + lenstr;  // krazy:exclude=doublequote_chars

Note

{{{1}}}


Compiler Warnings

In addition to the various Krazy tools, you can also get valuable assistance from the warnings that the compiler emits, especially if you enable additional warnings (per the documentation for your compiler), and also if you test with more than one compiler (e.g. if you can test on Linux with both GCC and the Intel compiler; or on Linux with GCC and also on Windows with the Microsoft compiler).