New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check with static code analyser #3342

Closed
kostyfisik opened this Issue Nov 2, 2016 · 43 comments

Comments

Projects
None yet
5 participants
@kostyfisik
Contributor

kostyfisik commented Nov 2, 2016

I have a one week trial of PVS-studio, there are quite a number places it the code that looks at least strange and some of them are for sure should be considered as a bug and probably should be inspected with some experienced developer. A short list:

/home/tig/dealii/dealii-git/include/deal.II/base/exceptions.h	42	warn	V690 The 'ExceptionBase' class implements a copy constructor, but lacks the '=' operator. It is dangerous to use such a class. 
/home/tig/dealii/dealii-git/include/deal.II/base/thread_management.h	2944	warn	V678 An object is used as an argument to its own method. Consider checking the first actual argument of the 'destroy' function. 
/home/tig/dealii/dealii-git/include/deal.II/algorithms/newton.templates.h	131	err	V672 There is probably no need in creating the new 'out' variable here. One of the function's arguments possesses the same name and this argument is a reference. Check lines: 96, 131. 
/home/tig/dealii/dealii-git/include/deal.II/lac/block_vector_base.h	214	warn	V690 The 'Iterator' class implements the '=' operator, but lacks a copy constructor. It is dangerous to use such a class. 
/home/tig/dealii/dealii-git/include/deal.II/lac/block_vector_base.h	2052	err	V568 It's odd that the argument of sizeof() operator is the 'this->n_blocks()' expression. 
/home/tig/dealii/dealii-git/include/deal.II/base/thread_management.h	2918	warn	V730 Not all members of a class are initialized inside the constructor. Consider inspecting: task_is_done. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/signals2/last_value.hpp	70	err	V607 Ownerless expression '* first'. 
/opt/centos/devtoolset-1.1/root/usr/include/c++/4.7.2/array	130	err	V557 Instantiate std_cxx11::array < char, 30 >: Array overrun is possible. The '_Nm' index is pointing beyond array bound./home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/archive/iterators/mb_from_wchar.hpp	125	err	V730 Not all members of a class are initialized inside the constructor. Consider inspecting: m_mbs. 
/home/tig/dealii/dealii-git/source/grid/cell_id.cc	25	err	V730 Not all members of a class are initialized inside the constructor. Consider inspecting: child_indices. 
/home/tig/dealii/dealii-git/source/multigrid/mg_level_global_transfer.cc	451	err	V758 The 'global_partitioner' reference becomes invalid when smart pointer returned by a function is destroyed. 
/home/tig/dealii/dealii-git/source/grid/grid_generator.cc	1740	warn	V560 A part of conditional expression is always true: dim > 1. 
/home/tig/dealii/dealii-git/include/deal.II/matrix_free/mapping_info.templates.h	393	warn	V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 391, 393. 
/home/tig/dealii/dealii-git/source/fe/fe_abf.cc	331	warn	V688 The 'cached_values' local variable possesses the same name as one of the class members, which can result in a confusion. 
/home/tig/dealii/dealii-git/include/deal.II/matrix_free/fe_evaluation.h	2665	err	V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. 
/home/tig/dealii/dealii-git/source/grid/grid_in.cc	296	err	V663 Infinite loop is possible. The 'cin.eof()' condition is insufficient to break from the loop. Consider adding the 'cin.fail()' function call to the conditional expression. 
/home/tig/dealii/dealii-git/source/grid/grid_out.cc	1475	warn	V656 Variables 'x_min', 'x_max' are initialized through the call to the same function. It's probably an error or un-optimized code. Consider inspecting the 'tria.begin()->vertex(0)[0]' expression. Check lines: 1474, 1475. 
/home/tig/dealii/dealii-git/source/grid/grid_out.cc	3220	err	V595 The 'q_projector' pointer was utilized before it was verified against nullptr. Check lines: 3220, 3250. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/math/policies/policy.hpp	1026	err	V562 It's odd to compare a bool type value with a value of 3: t1::value != user_error. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/math/special_functions/detail/fp_traits.hpp	304	err	V512 A call of the 'memcpy' function will lead to underflow of the buffer '& x'. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/math/constants/calculate_constants.hpp	693	warn	V760 Two identical blocks of text were found. The second block begins from line 701. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/math/special_functions/factorials.hpp	169	err	V547 Expression 'n >= 0' is always true. Unsigned type value is always >= 0. 
/home/tig/dealii/dealii-git/include/deal.II/lac/vector_operations_internal.h	254	err	V523 The 'then' statement is equivalent to the 'else' statement. 
/home/tig/dealii/dealii-git/include/deal.II/lac/la_parallel_vector.templates.h	59	warn	V728 An excessive check can be simplified. The '||' operator is surrounded by opposite expressions 'val == 0' and 'val != 0'.  
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/multi_index_container.hpp	843	err	V667 The 'throw' operator does not possess any arguments and is not situated within the 'catch' block. 
/home/tig/dealii/dealii-git/include/deal.II/fe/fe_dgp_nonparametric.h	602	warn	V703 It is odd that the 'degree' field in derived class 'FE_DGPNonparametric' overwrites field in base class 'FiniteElementData'. Check lines: fe_dgp_nonparametric.h:602, fe_base.h:296. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/unordered/detail/equivalent.hpp	53	warn	V690 The '=' operator is declared as private in the 'grouped_ptr_node' class, but the default copy constructor will still be generated by compiler. It is dangerous to use such a class. 
/home/tig/dealii/dealii-git/bundled/boost-1.62.0/include/boost/graph/graph_concepts.hpp	549	err	V530 The return value of function 'infinity' is required to be utilized. 
/home/tig/dealii/dealii-git/source/base/quadrature.cc	676	warn	V636 The 'subface_no / 2' expression was implicitly cast from 'int' type to 'double' type. Consider utilizing an explicit type cast to avoid the loss of a fractional part. An example: double A = (double)(X) / Y;. 
/home/tig/dealii/dealii-git/source/grid/manifold_lib.cc	486	warn	V592 The expression was enclosed by parentheses twice: ((expression)). One pair of parentheses is unnecessary or misprint is present. 
/home/tig/dealii/dealii-git/source/base/tensor_product_polynomials.cc	316	err	V596 The object was created but it is not being used. The 'throw' keyword could be missing: throw ExcNotImplemented(FOO); 
/home/tig/dealii/dealii-git/source/grid/tria.cc	6378	warn	V506 Pointer to local variable 'lines_x' is stored outside the scope of this variable. Such a pointer will become invalid. 
/home/tig/dealii/dealii-git/source/lac/sparsity_pattern.cc	234	err	V501 There are identical sub-expressions 'cols == 0' to the left and to the right of the '&&' operator. 
/home/tig/dealii/dealii-git/source/fe/fe_values.cc	2383	err	V523 The 'then' statement is equivalent to the 'else' statement. 
/home/tig/dealii/dealii-git/source/numerics/time_dependent.cc	866	warn	V636 The expression was implicitly cast from 'int' type to 'double' type. Consider utilizing an explicit type cast to avoid the loss of a fractional part. An example: double A = (double)(X) / Y;.

Full log file is attached. Checked after commit
" 0e395a1 2016-11-01 | Merge pull request #3339 from Rombur/exception"
pvs.txt

@drwells

This comment has been minimized.

Show comment
Hide comment
@drwells

drwells Nov 2, 2016

Member

I have seen PVS studio before but I never bothered to configure it to do this. Thanks!

I'll post again when I have read this more carefully.

Member

drwells commented Nov 2, 2016

I have seen PVS studio before but I never bothered to configure it to do this. Thanks!

I'll post again when I have read this more carefully.

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Nov 2, 2016

Member

Ah, that is very interesting. I bet that almost all of them are not really problems, but we should try to address them anyway or at least go through them.

There are reports about 161 files (cat Downloads/pvs.txt | perl -p -e 's/\t[0-9]+[ \t]*(err|warn).*//g;' | sort | uniq | wc -l) of which 36 are in source/ and 31 are in include/. The rest are in bundled/ or in system files that we will likely not want to change.

I think it would be quite interesting to create individual github issues for each of these 36+31 files. This would make it possible to track which ones have been addressed and which still need someone to look at it. @kostyfisik -- would you be interested in doing this? I bet you could use the hub program to script this (https://github.com/github/hub). If you use a title such as "Static analysis: source/grid/tria.cc" then they would be easy to search for. If you do that, also put a text such as "In reference to #3342" into the body so that it links back to here.

If you don't feel confident opening so many issues by a script, let me know and I can help out.

Member

bangerth commented Nov 2, 2016

Ah, that is very interesting. I bet that almost all of them are not really problems, but we should try to address them anyway or at least go through them.

There are reports about 161 files (cat Downloads/pvs.txt | perl -p -e 's/\t[0-9]+[ \t]*(err|warn).*//g;' | sort | uniq | wc -l) of which 36 are in source/ and 31 are in include/. The rest are in bundled/ or in system files that we will likely not want to change.

I think it would be quite interesting to create individual github issues for each of these 36+31 files. This would make it possible to track which ones have been addressed and which still need someone to look at it. @kostyfisik -- would you be interested in doing this? I bet you could use the hub program to script this (https://github.com/github/hub). If you use a title such as "Static analysis: source/grid/tria.cc" then they would be easy to search for. If you do that, also put a text such as "In reference to #3342" into the body so that it links back to here.

If you don't feel confident opening so many issues by a script, let me know and I can help out.

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Nov 2, 2016

Member

Start of a script:

FILES=`cat Downloads/pvs.txt | perl -p -e 's/\t[0-9]+[ \t]*(err|warn).*//g;' | sort | uniq | egrep '/home/tig/dealii/dealii-git/(include|source)'`
for file in $FILES ; do 
   echo "========= $file" ; 
   grep $file Downloads/pvs.txt ; 
done

The body of the loop would need to take the output of grep and pass it to hub.

Member

bangerth commented Nov 2, 2016

Start of a script:

FILES=`cat Downloads/pvs.txt | perl -p -e 's/\t[0-9]+[ \t]*(err|warn).*//g;' | sort | uniq | egrep '/home/tig/dealii/dealii-git/(include|source)'`
for file in $FILES ; do 
   echo "========= $file" ; 
   grep $file Downloads/pvs.txt ; 
done

The body of the loop would need to take the output of grep and pass it to hub.

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Nov 2, 2016

Contributor

Hub looks to be hard for a "do\forget" cycle. I found python script https://gist.github.com/JeffPaine/3145490 to create issues, however, I am overloaded at the moment (and will be for next 3 weeks), so probably someone else can script it in a proper way. I have done the scan just because I was reading news and found that due to release of Linux version of PVS they will provide a trial to anyone, you just need to e-mail them. And it was very easy to do the scan, just few commands. http://www.viva64.com/en/m/0036/

Contributor

kostyfisik commented Nov 2, 2016

Hub looks to be hard for a "do\forget" cycle. I found python script https://gist.github.com/JeffPaine/3145490 to create issues, however, I am overloaded at the moment (and will be for next 3 weeks), so probably someone else can script it in a proper way. I have done the scan just because I was reading news and found that due to release of Linux version of PVS they will provide a trial to anyone, you just need to e-mail them. And it was very easy to do the scan, just few commands. http://www.viva64.com/en/m/0036/

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Nov 2, 2016

Contributor

BTW, https://scan.coverity.com/github can be used for automated static code analysis with github integration as a Travis job...

Contributor

kostyfisik commented Nov 2, 2016

BTW, https://scan.coverity.com/github can be used for automated static code analysis with github integration as a Travis job...

This was referenced Nov 2, 2016

This was referenced Nov 11, 2016

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Nov 11, 2016

Member

My apologies for the noise. I'm going to wait for a while till I can open issues again, then do so for each file. Some of them may be duplicates.

Member

bangerth commented Nov 11, 2016

My apologies for the noise. I'm going to wait for a while till I can open issues again, then do so for each file. Some of them may be duplicates.

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Nov 11, 2016

Member

OK, sanity restored. My apologies for the mess (and the many emails everyone must have gotten)!

Member

bangerth commented Nov 11, 2016

OK, sanity restored. My apologies for the mess (and the many emails everyone must have gotten)!

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Dec 6, 2016

Contributor

BTW, PVS-Studio is free now to use with open-source projects free enough to add specially formatted comments to the source. See the details http://www.viva64.com/en/b/0457/

Contributor

kostyfisik commented Dec 6, 2016

BTW, PVS-Studio is free now to use with open-source projects free enough to add specially formatted comments to the source. See the details http://www.viva64.com/en/b/0457/

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Dec 6, 2016

Contributor

Putting it into Travis would be a next logical step if adding special comments can be accepted with deal.ii. However, this will obviously require masking of false positives...

Contributor

kostyfisik commented Dec 6, 2016

Putting it into Travis would be a next logical step if adding special comments can be accepted with deal.ii. However, this will obviously require masking of false positives...

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Dec 6, 2016

Member

But doesn't it take a long time to run the entire step? We can't put it into Travis if it takes more than a few minutes or up to half an hour, as then we'd never get through our patch load on some days...

Member

bangerth commented Dec 6, 2016

But doesn't it take a long time to run the entire step? We can't put it into Travis if it takes more than a few minutes or up to half an hour, as then we'd never get through our patch load on some days...

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Dec 6, 2016

Contributor

PVS has an incremental mode http://www.viva64.com/en/m/0024/

Contributor

kostyfisik commented Dec 6, 2016

PVS has an incremental mode http://www.viva64.com/en/m/0024/

@kostyfisik

This comment has been minimized.

Show comment
Hide comment
@kostyfisik

kostyfisik Dec 6, 2016

Contributor

I am not sure it is available for linux now, but I bet it can be at least discussed with PVS devs.

Contributor

kostyfisik commented Dec 6, 2016

I am not sure it is available for linux now, but I bet it can be at least discussed with PVS devs.

@bangerth

This comment has been minimized.

Show comment
Hide comment
@bangerth

bangerth Jan 3, 2017

Member

#3538 is the only open issue right now. I think that since we addressed all other ones, we can close this. We can always open a new issue (or reopen this one) if we have more to say here.

Member

bangerth commented Jan 3, 2017

#3538 is the only open issue right now. I think that since we addressed all other ones, we can close this. We can always open a new issue (or reopen this one) if we have more to say here.

@bangerth bangerth closed this Jan 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment