A new version of the static code analyzer cppcheck 2.6 has been released, which allows detecting various classes of errors in C and C++ code, including when using non-standard syntax typical for embedded systems. It provides a collection of plugins that ensure integration of cppcheck with various development, continuous integration, and testing systems, as well as capabilities such as checking code for compliance with styling guidelines. Both its own parser and an external parser from Clang can be used for code analysis. It also includes the donate-cpu.py script for providing local resources to perform collaborative code review for Debian packages. The source code of the project is distributed under the GPLv3 license.
The development of cppcheck focuses on identifying issues related to undefined behavior and the use of constructs that are hazardous from a security perspective. The goal is also to minimize false positives. Among the identified issues are: pointers to nonexistent objects, division by zero, integer overflows, incorrect bit-shift operations, erroneous type conversions, memory-related issues, improper use of STL, dereferencing null pointers, applying checks after actual access to the buffer, buffer overflows, and the use of uninitialized variables.
In the new version:
- The following checks have been added to the core analyzer:
- absence of a return statement in the function body;
- writing overlapping data, defining undefined behavior;
- the comparable value is out of the representable range of the type;
- copy optimization is not applied for return std::move(local);
- a file cannot be opened simultaneously for reading and writing in different streams;
- for Unix platforms, support for outputting diagnostic messages in different colors has been added;
- symbolic analysis for ValueFlow has been added. A simple delta is used to compute the differences between two unknown variables;
- the rules used for the list of tokens «define» may also apply to #include;
- The library tag can now contain the tag, and accordingly, functions like free that can take such containers, such as std::size, std::empty, std::begin, std::end, etc., can specify yield or action for the containers;
- The library tag can now contain the tag for smart pointers that have unique ownership. A warning is now issued for 'dangling' references to such smart pointers;
- Fixed issues with the parameter ācppcheck-build-dir;
- htmlreport can now output author information (using git blame);
- The warnings about variables that are not constant but could be have been expanded;
- Resolved accumulated bugs and shortcomings in the analyzer.
Additionally, full checks from Misra C 2012 have been implemented, including Amendment 1 and Amendment 2, except for rules 1.1, 1.2, and 17.3. Checks 1.1 and 1.2 must be performed by the compiler. Check 17.3 can be performed by the compiler, for example, GCC.
Source: opennet.ru
