Closed kostyfisik closed 7 years ago
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.
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.
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
.
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/
BTW, https://scan.coverity.com/github can be used for automated static code analysis with github integration as a Travis job...
OK, enough spam -- github blocked me after these first few issues with a message that says "You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later."
Anyway, here's the script if someone wants to take over:
for file in $FILES ; do echo "========= $file" ; ./ghi open -m "Static analysis: $file
\`\`\`
`grep $file ~/Downloads/pvs.txt`
\`\`\`
We should address these warnings and errors from the static analysis tool PVS. In response to #3342." -L"Low priority" -L"Starter project" ; done
And the ghi script is from here:
curl -sL https://raw.githubusercontent.com/stephencelis/ghi/master/ghi > ghi
The following entries of $FILES
were not processed because of the error:
dealii-git/source/base/function_parser.cc
dealii-git/source/base/logstream.cc
dealii-git/source/base/quadrature.cc
dealii-git/source/base/quadrature_lib.cc
dealii-git/source/base/tensor_product_polynomials.cc
dealii-git/source/base/timer.cc
dealii-git/source/dofs/dof_tools_constraints.cc
dealii-git/source/fe/fe_abf.cc
dealii-git/source/fe/fe_nedelec.cc
dealii-git/source/fe/fe_q_base.cc
dealii-git/source/fe/fe_q_hierarchical.cc
dealii-git/source/fe/fe_raviart_thomas.cc
dealii-git/source/fe/fe_values.cc
dealii-git/source/fe/mapping_cartesian.cc
dealii-git/source/fe/mapping_fe_field.cc
dealii-git/source/fe/mapping_manifold.cc
dealii-git/source/fe/mapping_q_generic.cc
dealii-git/source/grid/cell_id.cc
dealii-git/source/grid/grid_generator.cc
dealii-git/source/grid/grid_in.cc
dealii-git/source/grid/grid_out.cc
dealii-git/source/grid/manifold_lib.cc
dealii-git/source/grid/tria.cc
dealii-git/source/lac/solver_control.cc
dealii-git/source/lac/sparse_direct.cc
dealii-git/source/lac/sparsity_pattern.cc
dealii-git/source/lac/sparsity_tools.cc
dealii-git/source/multigrid/mg_level_global_transfer.cc
dealii-git/source/multigrid/multigrid.cc
dealii-git/source/numerics/data_out.cc
dealii-git/source/numerics/data_out_rotation.cc
dealii-git/source/numerics/time_dependent.cc
Add a random delay between submissions 1h+rand(20min)? According to existing history 30 issues a day are a valid number
The limit is 60 requests per hour https://developer.github.com/v3/#rate-limiting
This way two min delay should be for sure safe :)
As soon as @bangerth actively started to remove "smell" from detected places - I am going to run the analyzer once more, probably on 7th November, just before my trial period expires.
It would be nice if you can put some label on issues, where the analyzer was mistaken like here https://github.com/dealii/dealii/issues/3378 I will forward this cases to PVS devs, so the next time someone will try to run PVS against deal.ii this will not give a false positive.
I can try to mention here ones that were mistaken, but I think the majority are actually valid points.
We should also see how far we can get within a week in addressing these issues. Any help appreciated!
The second mentioning does not work. Mentioning #3378 again. I believe this is a good thing to provide back a short report to PVS on this usage. For sure they would prefer someone buying a license, however, some knowledge on possible weak sides of PVS should also be valuable.
The updated check attached. The diff is really impressive! It looks like that I have 2 days of trial left, so I will try not to forget to run the check about 40 hrs later...
revision checked: fd6ab4 2016-11-07 | Merge pull request #3485 from bangerth/remove-duplicate-variable (HEAD, origin/master, origin/HEAD, master) [Denis Davydov]
Issues with some disscusion about why not to fix warnings:
It looks like PVS is still complaining about #3356. Any idea?
Nice work everyone :tada:
Yes, we've made good progress on closing these -- nice teamwork :-)
@kostyfisik -- is it complicated to set up running PVS on a project? Would you be interested on running it also on ASPECT? (http://aspect.dealii.org, https://github.com/geodynamics/aspect) I will fully understand if you don't want to do it, though!
@bangerth The PVS setup on Linux is very simple - install PVS binary (yum install pvs-studio-VERSION.rpm
) and (using my path):
cd dealii-git/
git pull
cd ..
cd dealii-build/
rm -rf *
cmake -DCMAKE_INSTALL_PREFIX=/home/tig/dealii/dealii /home/tig/dealii/dealii-git
cp ~/jade/PVS-Studio.lic ./
pvs-studio-analyzer trace -- make -j12 install
pvs-studio-analyzer analyze -l PVS-Studio.lic -o pvs.log -j12
plog-converter -a GA:1,2 -t tasklist -o pvs2.txt pvs.log
The problem is that I was spent 10 minutes to cmake
Trilinos without any success, as soon as I need to be able to compile Aspect beforehand. I had downloa cmake -DCMAKE_INSTALL_PATH=/home/tig/trilinos /home/tig/trilinos-rel
and make
leads to nothing.
Actually it should not be a problem to get a Linux trial now, PVS devs looks to be quite friendly. Follow "contact" link in the annoncement http://www.viva64.com/en/b/0441/
OK, thanks for the detailed instructions. I may try this sometime over the winter break :-)
@bangerth I have alreade mentioned, here is the link to Coverty static analyzer https://scan.coverity.com/github It can be run as Travis-CI job to do analysis as you commit... And it is free for open-source projects.
BTW, just a bit of statistics, Initial pvs.txt has 173 messages, related to dealii, with 1.55 mln LoC which gives us estimated bug density of 0.11 per 1000 LoC - this is far less than 0.75 average (for open source with more than 1 mln LoC) and beats Linux kernels 0.59! Deal.ii rocks! :) https://www.helpnetsecurity.com/2013/05/07/analyzing-450-million-lines-of-software-code/
pvs3.txt has 49 messages, so now it formally even better now! (keep in mind, that most of these 49 seem to be false positive, this means outstanding quality!).
1728ec0 2016-11-07 | Merge pull request #3499 from kronbichler/remove_memory_consumption_test
Ha, these are interesting statistics! I think I always knew that we had fairly good code quality, but it's nice to see some actual statistics about this!
It looks like we're down to one issue, #3353. @Rombur -- what's your suggestion how we should proceed with that one?
@bangerth I posted a short report to PVS and requested on the trial in winter. Feel free to contact support@viva64.com as soon as you are ready to put your hands on PVS testing, they will issue you a trial license in a short period of time.
I can confirm that it's indeed easy to get a week trial licence for PVS by writing an email. Playing around with it now...
@davydden Probably you can do the test of ASPECT if you have a trilinos installed.
I`ve got (sorry, it happened after the trial was over) an idea that it can be also interesting to run tests of the deal.ii competitors - just to better understand if it is valid to claim that deal.ii has the best codebase?
Two fast tests: 1) mfem - seems to be extremely lightened but powerful from LLNL http://mfem.org/ and very easy to build and check with PVS (I tested first two commands) - due to the origin - zero messages?
make config
pvs-studio-analyzer trace -- make all -j12
pvs-studio-analyzer analyze -l PVS-Studio.lic -o pvs.log -j12
plog-converter -a GA:1,2 -t tasklist -o pvs.txt pvs.log
2) http://www.freefem.org/ - I think that this FEM package has the most academic impact around open sourced FEM (as I was looking references to deal.ii, FreeFem++, and many others in scopus database). While it seems to be not so big project (about 130 KLoC) I would expect many errors (during compilation I so many warnings).
to check I had to sudo apt-get install bison flex
first, after that
./configure
pvs-studio-analyzer trace -- make -j6
Two long runs: 3) libMesh - the only one comparable in code base https://github.com/libMesh/libmesh check should be easy (no dependences, so just configure and pvs trace make). 4) https://fenicsproject.org/ - like deal.ii it has a Wilkinson Prize (in 2015), Python interface and can scale up to 24k core (confirmed scaling). However, putting it via PVS can be hard (the custom build script is hard to understand).
I am trying to run analyzis on deal.II
pvs-studio-analyzer trace -- make all -j12
with license file in the build folder, but have error
No compilation units found
Analysis finished in 0::0::00.00
@kostyfisik any ideas?
trying with JSON now...
@bangerth @drwells @Rombur btw, i think we need to run the whole test suite through PVS. Because (from http://www.viva64.com/en/m/0036/)
It is important to understand that all files to be analyzed should be compiled. If your project actively uses code generation, then this project should be built before analysis, otherwise there may be errors during preprocessing.
So anything that is header only, won't get checked as far as I understand.
Valid point. Though I suspect that we instantiate most everything that's in one header or another through one of the .cc
files we have. Maybe not for all possible template arguments, but for some at least, and that should uncover most errors I think.
Agreed, there are very few classes which are header-only, for example I picked up this warning for Parpack when compiling my library:
/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/dealii-develop-s3q44glws4wtxtqcyscogri3blotqm5j/include/deal.II/lac/parpack_solver.h 526 err V730 Not all members of a class are initialized inside the constructor. Consider inspecting: lworkl, nloc, ncv, ldv, ldz, lworkev.
@davydden lic file does not matter for trace build... Are you doing the build from the empty directory? Another point is that there are no valid all
target for deal.ii, the correct command was pvs-studio-analyzer trace -- make -j12 install
JSON worked. So here is my output for deal.II configured with gcc 5.4.0, 32bit integers and all optional packages (Filtered messages: 245
, so it looks like it picked up more than what @kostyfisik has in his last analysis).
To reproduce, the steps are
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On <blah-blah-blah> ../
$ make all -j8
$ pvs-studio-analyzer analyze -l PVS-Studio.lic -o pvs.log -j8
$ plog-converter -a GA:1,2 -t tasklist -o pvs_tasks.txt pvs.log
p.s. i don't know why PVS did not do analysis from strace
output for me. Maybe some size limitation, the file was around 0.5Gb.
BTW, it looks like for static analysis you should compile deal.ii in debug mode only. At least for Clang it is explicitly recommended to do so, as soon as they use asserts to eliminate false positives, I think that PVS should be clever enough to do it too.
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.
OK, sanity restored. My apologies for the mess (and the many emails everyone must have gotten)!
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/
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...
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...
PVS has an incremental mode http://www.viva64.com/en/m/0024/
I am not sure it is available for linux now, but I bet it can be at least discussed with PVS devs.
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:
Full log file is attached. Checked after commit " 0e395a1 2016-11-01 | Merge pull request #3339 from Rombur/exception" pvs.txt