Summer is not only a holiday season, but also time of fruitful work. Sunny days are so inspiring that there's enough energy both for late walks and large code commits. The second summer PVS-Studio 7.04 release turned out to be quite large, so we suggest for your attention this press release, in which we'll tell you about everything.
PVS-Studio is a tool designed to detect errors and potential vulnerabilities in the source code of programs, written in C, C++, C#, Java. It works in Windows, Linux, and macOS environment.
An extensive collection of errors found in code during the checks of various open source projects clearly demonstrates the abilities of the analyser.
Here's an overview of new features coming with the PVS-Studio 7.04 release.
When working on a task developers take code from so many various places. A popular source of Copy-Paste code is the Stack Overflow website and similar ones. There are cases when a developer takes the code from an open source project and doesn't check license requirements. Thus, a closed source project may accidentally get a few files from an open source project with a Copyleft license, which obliges to make the entire project code open source. In companies with a large number of employees, it's difficult to keep track of this, whereas such actions might cause adverse risks and problems. So, PVS-Studio now has a diagnostic, which will help to find such files. It relates to all supported languages (C, C++, C#, Java).
Diagnostic numbers for different languages:
Let's take a closer look at these diagnostics and figure out what they are made for. An example of a comment that the analyser will issue a warning to:
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
If you add a file with such a license (in this case, GPL3) in a closed project, you'll have to open the rest code due to specifics of this license.
Such a type of licenses is called "viral" because of their ability to extend to the rest of the project files. The problem is that usage of at least one file with such a license in a closed project automatically makes the entire source code open and obliges to distribute it along with binary files.
The diagnostic is looking for the following "virus" licenses:
Here are the options of what you can do in case if you detect usage of files with a copyleft license in a closed project:
We understand that this diagnostic is inappropriate for open source projects. The PVS-Studio team contributes to developing of open source projects, helps to fix errors in them and provides free license options. However, our product is a B2B solution and therefore this diagnostic is enabled by default.
If your code is distributed under one of the copyleft licenses above, you can disable this diagnostic in the following ways (for C\C ++ it is V1042):
For C# V3144 is a corresponding number of a diagnostic, V6071 - for Java.
In case if you know other types of "virus" licenses that PVS-Studio doesn't detect at this point, you're welcome to let us know through our feedback form. We'll add them in the next release.
I'd like to give special attention to the diagnostic with the number V1040. We managed to find an interesting error in the library of the well-known CMake project even at the beta stage:
V1040 Possible typo in the spelling of a pre-defined macro name. The '__MINGW32_' macro is similar to '__MINGW32__'. winapi.h 4112
/* from winternl.h */
#if !defined(__UNICODE_STRING_DEFINED) && defined(__MINGW32_)
#define __UNICODE_STRING_DEFINED
#endif
There's a typo made in the name __MINGW32_. At the end, one underline character is missing. If you search the code with this name, you can see that the version with two underline characters on both sides is used in the project:
You can check out all found errors in the CMake project in the article: "CMake: the case when the project's quality is unforgivable".
As for the C# analyser, we added evaluation of read\written values from property getters and setters, as well as from async methods.
We're currently working on improvement of monitoring fields' values and properties of objects as they are passed to methods, as well as monitoring the contents of turples. These improvements will be available in the next analyser release.
It has been almost 2 years since the last release of the LTS-version of SonarQube 6.7. The new version was eagerly awaited starting with the SQ 7.x and when LTS was released, users began to actively switch to it, which caused various problems. Soon SQ 7.9.1 LTS came out with minor fixes and third-party plugin developers also made patches.
Fortunately, the PVS-Studio plugin had only one problem, related to switching to Java 11, which was quickly fixed and our clients immediately switched to a workable version.
We're also kept compatibility with old SonarQube versions and the list of supported versions now looks as follows: SonarQube 6.7 LTS and later
The PVS-Studio plugin only converts analysis results into the format of the SonarQube database. In other words, it just downloads results of PVS-Studio analysis in SQ. To get the SonarScanner utility operate fully, you need to have plugins for programming languages installed. We didn't start to develop what already exists, so we just add support of already existing popular plugins. In this version, we've added compatibility with Sonar C Community and SonarCFamily language plugins.
The entire list of supported language plugins looks like this:
To upload the results of the PVS-Studio analysis it is enough to install at least one plugin from this list. Most users install only Sonar C++ Community, SonarC# or SonarJava. The rest plugins may be needed for more specific projects.
When choosing plugins, consider the fact that Community plugins aren't compatible with SonarCFamily. But if you use only SonarQube Community Edition, there will be no such problem.
Previously, one could configure the analyser only through the configuration file sonar-project.properties. There are no complaints about this method. It's very convenient and is used 99% of time, but we've made an additional settings page in Administration > Configuration > PVS-Studio on SonarQube's server side, as it can be a preferably used for some scenarios.
The settings page looks like this:
When setting configurations in two ways, the ones specified in the file sonar-project.properties are of highest priority.
Releases of new IntelliJ IDEA and PVS-Studio versions differ in dates. Recently we've had a situation when IntelliJ IDEA 192.* was released but the PVS-Studio plugin couldn't be installed in it. In this release, we've added support for the latest IntelliJ IDEA versions, as well as refinements to avoid similar problems in the future.
PVS-Studio Plugin
PVS-Studio Plugin is meant for publishing reports of the PVS-Studio analyser results in the Jenkins continuous integration system in the HTML format. Previously, this plugin was only available to Windows users because it called the report converter automatically and did it only for Windows. In PVS-Studio 7.04, the plugin supports only HTML-reports that have to be generated in a single step, but this measure made the plugin cross-platform.
Warnings NG Plugin
For Jenkins, there is a useful plugin Warnings Next Generation Plugin for viewing analysis results from various tools. We've recently added PVS-Studio support in it. The ability to load the PVS-Studio analysis results using this plugin became available in the 6.0.0, its release accidently coincided with the PVS-Studio 7.04 release:
PVS-Studio_Cmd
PVS-Studio_Cmd.exe now has a special operational mode - credentials. This mode enables you to create a settings file and enter license information without using a GUI interface (for example, Visual Studio plugin or C and C++ Compiler Monitoring UI utility). This mode is especially relevant when used on a build server (where GUI utilities may be absent), in containers, when integrating with cloud solutions.
Analysis of Unreal Engine Projects
We added the option AutoloadUnrealEngineLog in the PVS-Studio plugin for Visual Studio which enables you to automatically upload the analyser report in the PVS-Studio output window after the analysis. Without this option, the log must be uploaded manually through the plugin menu.
Also the documentation section "Analysis of Unreal Engine projects" describes changes of standard build scripts that allow you to build and analyse in one action. Without scripts modifications (when adding the flag -StaticAnalyzer=PVSStudio to launch arguments) the project is only analysed, not built.
CLMonitor
For the CLMonitor utility, we've added the ability to monitor compiler runs for a specific process. This will let you monitor compiler runs, related only to a specific project, even during parallel builds of several projects. To work in this mode, the flags ‑‑parentProcessID %PID% (CLMonitor monitors processes child-related to the specified one) and ‑‑attach (CLMonitor monitors processes child-related to a current console) are used.
pvs-studio-analyzer
The ‑‑ignore-ccache flag is added in the pvs-studio-analyzer utility, which is meant for checking projects in Linux and macOS:
pvs-studio-analyzer analyze ... --ignore-ccache ...
If the ccache utility is used in a project build, PVS-Studio is operating in the incremental analysis mode. To check the entire project without resetting the cache of the ccache utility, choose this flag.
Subscribe to be informed about our new publications:
PVS-Studio: