Static code analizers

Status
Not open for further replies.

jDev

Seniorius Lurkius
3
Hello guys,

Some days ago our CTO decided to start using one of static analysis tools to improve our code base quality. We decided to start testing for the tool from the leader of the market - Coverity and though this tool demonstrated good results, we found it too expensive. We do not have enough time to test all possible static analysis tools so I would really appreciate if you share some personal knowledge or useful articles.

For example, I found only one useful independent article by John Carmack (http://gamasutra.com/view/news/128836/I ... alysis.php). But this article includes only two tools PVS-Studio and PC-lint and it’s rather old.

Thank you for your advice.
 

Drizzt321

Ars Legatus Legionis
34,922
Subscriptor++
[url=http:/civis/viewtopic.php?p=29290125#p29290125:2ci69tdp said:
jDev[/url]":2ci69tdp]
For example, I found only one useful independent article by John Carmack (http://gamasutra.com/view/news/128836/I ... alysis.php). But this article includes only two tools PVS-Studio and PC-lint and it’s rather old.

I hadn't seen that, great read, thanks!

And this actually made me check Go lang, which I have an interest in starting a small personal project with. Some day. And there is static analysis built-into one of the language tools :) (https://golang.org/lib/godoc/analysis/help.html if anyone is interested)
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
[url=http:/civis/viewtopic.php?p=29296081#p29296081:2d87jktc said:
jDev[/url]":2d87jktc]
[url=http:/civis/viewtopic.php?p=29292427#p29292427:2d87jktc said:
david_a[/url]":2d87jktc]What language/platform?
We are working in C/C++ in Visual Studio. So it is preferable that analyzer can be embedded in VS.

My impression is that, in this space, you Coverity or CoHome.
Ahem, sorry.

They are super expensive I think because there is no effective competition if you want ridiculously good signal to noise ratio off the bat, as the barrier to entry there is enormous (you need to have a huge corpus of real world code to work against AFAICT), and they factor into their cost a significant effort on their part to adapt to your code if it exhibits new classes of errors/high rates of false positives.

I think there are free trial versions of most of the rest, so it's totally worth someone's time running through them against your code base to try it all out before deciding.

Someone did an SO list (that got closed) but covered most of what you would want to look at.

If you found one that did well please do report back here, I suspect many people also would balk at Coverity's pricing too, and would tolerate a bit worse, for a bit less (though such trade offs may not exist).
 

BobTheFourth

Ars Praefectus
5,476
Subscriptor
We used to use Coverity at my company, but stopped because of the cost. We've been using Cppcheck for a couple of years now. Its OK, but I don't feel like it detects nearly as many things as Coverity did. But its free, so there's that.

Since its a simple command-line tool, its easy to integrate into build & source control systems. For instance, our SVN server runs it as a pre-commit hook and rejects commits that have "errors". I believe it can be built for Windows, though we're using it in a Linux environment.

I think you get what you pay for in this area, but if cost is a big problem, then it might be worth looking into.
 

jDev

Seniorius Lurkius
3
Someone did an SO list (that got closed) but covered most of what you would want to look at.

Thank you for the useful link. I believe it is worth time to test different analizers. Also I have found some quick review from NASA about CodeSonar/Klocwork: https://www.nasa.gov/sites/default/file ... 400_d3.pdf and unreal engine post: https://www.unrealengine.com/blog/how-p ... gines-code

Of course, I'll share my company choice. Now we are testing.
 

david_a

Ars Scholae Palatinae
819
Subscriptor++
Interesting how two of the most prominent writeups are for game engines :)

It makes sense though - with their domain writing automated tests probably don't add enough value for the complexity/time cost (I'm not sure how you write unit tests for a graphical engine anyway). I'm not so sure about Carmack's contention that code reviews / pairing aren't worth it, but I can definitely see the appeal of a completely automated solution to them.
 

MilleniX

Ars Tribunus Angusticlavius
8,138
Subscriptor++
Oh, also much more recently, Facebook Infer. Much more limited scope compared to the other tools mentioned so far, but based on much more modern analysis techniques that can let it go faster and provide better descriptions of what it's found. The combination of its narrow focus and newer methodology should also keep false positives very low. I haven't tried it yet, because its C++ support is so far minimal.
 

Afty

Ars Scholae Palatinae
1,434
At Google we use a combination of Clang/LLVM with -Werror and a curated set of warnings on by default, so that you can't compile with certain errors, and clang-tidy for analysis at code review time. We have an internal team that builds new warnings/checks based on the Clang infrastructure and pushes them back to the upstream project.

Re: the Clang Static Analyzer -- My understanding is that it is focused toward Objective-C (it was built by Apple for use in XCode) and that C++ support is not production quality. We don't use it at Google for C++, FWIW.
 

david_a

Ars Scholae Palatinae
819
Subscriptor++
[url=http:/civis/viewtopic.php?p=29342443#p29342443:16eylwmp said:
Optikal256[/url]":16eylwmp]In the Java (and increasingly the C#) world, http://www.sonarqube.org/ seems to be the goto tool. It looks like it also does C\C++ although I've never tried.
I'm having a hard time finding specifics of what it actually looks for. I found this page which makes it seem like it's similar to the analysis that tools like ReSharper provide. Although I guess that is technically static analysis, tools like Klocwork/Coverity are capable of finding much deeper issues like threading problems. I didn't know Sonar could do that though; I just thought it was some tool-aggregator-dashboard thing.
 
[url=http:/civis/viewtopic.php?p=29296081#p29296081:1dm7gxjj said:
jDev[/url]":1dm7gxjj]
[url=http:/civis/viewtopic.php?p=29292427#p29292427:1dm7gxjj said:
david_a[/url]":1dm7gxjj]What language/platform?
We are working in C/C++ in Visual Studio. So it is preferable that analyzer can be embedded in VS.
Two really easy things to do are turning up the warning level on your compiler, if you don't already, and enabling /analyze, Microsoft's static analyzer which is built into their compiler.
 

zeotherm

Ars Legatus Legionis
10,960
Moderator
We were told by higher up that we will be using Klocwork, even though we had seen and loved what Coverity showed us. That was last December. It is now July and we have yet to have our code run through a Klocwork server. Although this admittedly could be as much of an indication of our global IT people as it is Klocwork, but everything I read about them suggests that C# is a mere after thought.
 
Status
Not open for further replies.