Guidelines and HOWTOs/Code Checking: Difference between revisions

From KDE Community Wiki
*>Bhards
*>Bhards
Line 4: Line 4:
===The KDE 'Krazy' Checker===
===The KDE 'Krazy' Checker===
KDE developers have a simple set of tests that are collectively known as "Krazy".
KDE developers have a simple set of tests that are collectively known as "Krazy".
====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:
<code cppqt>
QString mystring;
mystring += "/";
</code>
will be flagged by the doublequote_chars checker, because it is more efficient to add a single char, as shown below:
<code cppqt>
QString mystring;
// note that we are using single quotes - this is a char, not a char array
mystring += '/';
</code>
That same checker will produce a false positive for code that looks like:
<code cppqt>
std::string mystring;
mystring += "/";
</code>
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:
<code cppqt>
  lenstr = "0" + lenstr;
</code>
becomes
<code cppqt>
  lenstr = "0" + lenstr;  // krazy:exclude=doublequote_chars
</code>
{{Note|C style comments like the following will ''not'' work:
<code cppqt>
  lenstr = "0" + lenstr;  /* krazy:exclude=doublequote_chars */
</code>
}}


===Compiler Warnings===
===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).
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).

Revision as of 02:33, 4 January 2007

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".

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).