📜 ⬆️ ⬇️

Static analysis of C ++ code

For me, the beauty of C ++ lies primarily in the permissiveness and terrifying power of the language. We can work with memory as tightly as in C, and at the same time we have such means of abstraction as templates and STL, where you can parameterize anything and anything.
The fee for this is appropriate - not always intelligible compiler errors (try to forget to put a semicolon after determining the class), a very long period of preparation and training of programmers, but most importantly, some bugs become visible only during the execution of the program.
We want more useful versions before launching our programs. One of the means of obtaining the desired - static code analysis. Static means not running the program. Not only probable errors, cases of undefined behavior, memory leaks are interesting, but also things like inaccessible / unused code, recommendations for enhancing the intuitiveness of the programming style.

Means for obtaining software metrics extracted by static analysis methods are not considered in this article. Remarks related to programming standards (the curly bracket should be on a separate line, oooooooh !!) are not interesting either.
The evaluation criteria are simple - the number and usefulness of the found bugs, ease of use (in particular, the absence of code modification requirements), free / reasonable price / good crack.
We carry out a primary review and give a bundle of links to the surface:


Found things


Gcc pedant keys


First of all, it is necessary to use all possible regular means. gcc provides the following interesting clues related to increasing compiler and preprocessor vigilance.

Of course, not himself so clever, but read everything here in this man-article about the keys associated with the warnings

Cppcheck


Perhaps the most worthy of the programs found.
The official site of the program and its plug-in for eclipsoids. It recognizes quite a lot, finds the following errors:
It is possible to mark classes as smart pointers (so as not to report on false memo cards), a GUI on Qt4.

Vera ++


Vera ++ , unlike cppcheck, is focused on style checking. It has an updated rule base. By default, there are a lot of really idiotic pieces like “there must be a space before the colon” ​​in the database. The only useful feature is a ban on using the namespace in header files. Rules, however, you can write yourself in the Tcl language. :)
')

Rats


RATS tells pretty convincing horror stories about security and buffer overflow attacks. I didn’t intently look at it because I don’t know very much about the protected code.

Checkers for C without pluses


Surprisingly, pure C programmers seem to care more about static analysis. Here we have a list of one and two

Will they be useful for positive developers? If you have code without classes and you remember which C ++ programs will not be built with the C compiler, then why not?

Splint


Such a thing is for pure C. It is assembled with little or no effort, but it works cleanly and is looking for a lot of things - see the manual.

Simian


Simian - similarity analyzer. Looking for duplicate code, it means. Honestly, I did not come up with her application

CIL


CIL - With Intermediate Language. Compiles C to simplified C! Simplified C can already be fed to other analyzers, which theoretically should improve the quality of their work.

Incomprehensible, oftopic




Trial / Cracked Software


A little of his such. Many analyzers are worth a lot of dollars and do not have cracks.
Here is an example of such an analyzer, you can go to their website and ask for trials of Cleanscape . The possibilities are not much different from cppcheck.

What else would you like


Not all errors in the code that are amenable to static analysis were presented in existing programs. And I would like to:

Source: https://habr.com/ru/post/75123/


All Articles