PVS-Studio is a static code analyzer that detects errors and potential vulnerabilities in the source code of programs written in C/C++/C#. Version 6.16 has obtained 11 new general analysis diagnostics.
- V789. Iterators for the container, used in the range-based for loop, become invalid upon a function call.
- V790. It is odd that the assignment operator takes an object by a non-constant reference and returns this object.
- V791. The initial value of the index in the nested loop equals ‘i’. Consider using ‘i + 1’ instead.
- V792. The function located to the right of the ‘|’ and ‘&’ operators will be called regardless of the value of the left operand. Consider using ‘||’ and ‘&&’ instead.
- V793. It is odd that the result of the statement is a part of the condition. Perhaps, this statement should have been compared with something else.
- V794. The copy operator should be protected from the case of this == &src.
- V795. Note that the size of the ‘time_t’ type is not 64 bits. After the year 2038, the program will work incorrectly.
- V796. A ‘break’ statement is probably missing in a ‘switch’ statement.
- V797. The function is used as if it returned a bool type. The return value of the function should probably be compared with std::string::npos.
- V798. The size of the dynamic array can be less than the number of elements in the initializer.
- V799. The variable is not used after memory has been allocated for it. Consider checking the use of this variable.
And three diagnostics for microoptimization:
- V818. It is more efficient to use an initialization list rather than an assignment operator.
- V819. Decreased performance. Memory is allocated and released multiple times inside the loop body.
- V820. The variable is not used after copying. Copying can be replaced with move/swap for optimization.
In a sense, this is a milestone for us. The thing is that we cannot add more numbers of general analysis warnings, otherwise they will concur with the numbers of micro-optimization diagnostics. It seemed to us that the list of 300 diagnostics was endless, but now it is over and we got to the point of 800, where we have micro-optimization diagnostics. In the next release we plan to resume numbering the general-analysis warnings with V1000.
Besides creating new diagnostics, we improve the already existing diagnostics. This time the improvements were made in the following diagnostics: V512, V519, V522, V558, V575, V576, V586, V591, V597, V601, V607, V611, V630, V641, V675, V676, V724, V728, V730, V769, V773, V779.
We made several edits allowing to check the code of the Tizen operating system. We will go back to the check of Tizen many times. Soon there will be at least 2 articles on this topic.
I suggest downloading the new version of the analyzer.
An always up-to-date list of articles describing errors that we find in open source projects with PVS-Studio analyzer – https://pvs-studio.com/en/blog/inspections/.