Bug 379502

Summary: Checking the code of Valgrind dynamic analyzer by a static analyzer
Product: [Developer tools] valgrind Reporter: Andrey Karpov <karpov>
Component: generalAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: minor CC: philippe.waroquiers, rhyskidd
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Andrey Karpov 2017-05-04 09:07:57 UTC
We regularly check various projects to spread the word about static analysis methodology in general, and about our tool PVS-Studio in particular, so I couldn't miss a chance to check the Valgrind project. Here are interesting fragments that I managed to notice, perhaps, something should be fixed: https://www.viva64.com/en/b/0504/
Comment 1 Julian Seward 2017-05-10 08:56:31 UTC
Can you make a patch that fixes at least the more obvious problems
(the ?: precedence ones in particular) ?
Comment 2 Andrey Karpov 2017-05-10 12:55:37 UTC
Yes, we can make patches, but I think it's not a very good idea. We don’t know the code much and can fix it incorrectly. And we have no opportunity to deal with every warning in detail. We regularly write articles about various projects, and we just don't have enough time to create such a large number of patches. Let me explain this with numbers. Now we have 11037 errors in the base ( https://www.viva64.com/en/examples/ ). If we start making patches for all of them, we’ll have to hire a whole new team for this. We aren’t that rich yet to do it. :)

P.S. If you want, I could give a PVS-Studio license for Valgrind Team. I should warn right away, that there will be a lot of false positives. Most of all they will be caused by active usage of macros. If you are interested, contact me at karpov[@]viva64.com.
Comment 3 Philippe Waroquiers 2017-05-15 21:02:51 UTC
Thanks for reporting these suspicious pieces of code.
I fixed 2 of the reported errors:
-                 (info = NULL ? "" : info));
+                 (info == NULL ? "" : info));

and
-                taken_Jccs, taken_Jccs * 100.0 / total_Jccs ?: 1);
+                taken_Jccs, taken_Jccs * 100.0 / (total_Jccs ? total_Jccs : 1));
 
in revision 16379.

Keeping the bug opened, as other reported problems still to be looked at.
Comment 4 Rhys Kidd 2017-05-25 15:58:04 UTC
Thanks Andrey. viva64 have some good tools that have helped in the past.