Static Code Analysis Tools? 87
rewt66 asks: "We are looking for a good static analysis tool for a fairly large (half a million lines) C/C++ project. What tools do you recommend? What do you recommend avoiding? What experience (good or bad) have you had with such tools?"
Prodev Workshop (Score:4, Informative)
http://www.sgi.com/products/software/irix/tools/p
Looks like it's IRIX only though, so YMMV, to put it mildly.
LLVM (Score:2, Informative)
http://llvm.org/ [llvm.org]
PreFast (Score:2, Informative)
Just add the
It's the tool that is used by MS to test its own code, known internally as PreFast.
It helped me find many bugs in other people's code.
Re:FindBugs (Score:2, Informative)
C/C++ checkers:
http://www.coverity.com/ [coverity.com] (commercial)
http://www.dwheeler.com/flawfinder/ [dwheeler.com] (OSS)
Coverity (Score:5, Informative)
They have excellent checks as well as the best framework for creating custom tests that I have ever come across.
NOTE: I am not affiliated with coverity, just a very satisfied user.
FlexeLint / PC-lint (Score:5, Informative)
http://www.gimpel.com/html/lintinfo.htm/ [gimpel.com]
I've never tried it for a code base as large as 500k. My guess it that I used it up to 15k. I was very pleased with it. I agreed with just about every warning it raised, and was able to easily suppress individual instances or whole classes of errors. I also found it somewhat easier to get started with compared to the big tools from Rational et al.
I think it's a bit pricey for a an open-source coder like me, but it should be cheap enough for a company with a tools budget.
Careful what you wish for (Score:2, Informative)
C and C++ Static Analysis tools (Score:3, Informative)
I work on a C/C++ code base that is a lot bigger than 500k lines. I've worked with results produced by Klocwork [klocwork.com] and also with the output from Reasoning [reasoning.com]. Both of these services/packages will cost you money but both provide good insight into your code. The commercial packages generally produce more focused results with less false-positives, so while they cost you money up front, your developers will spend less time weeding out the noise.
If paying money out for a commercial package isn't your thing, don't overlook the old standby lint or splint [splint.org], an updated successor.
Also well worth investigating to see how your code is actually running is Valgrind and it's associated tools [valgrind.org]. The Valgrind toolkit will give you a good idea where memory is being leaked, where variables and pointers are going off the rails. Valgrind hooks into a running program, so it's important to make sure that you test all the corners of the codebase if you go this route.
Cheers,
Toby Haynes
Purify (Score:3, Informative)
A coworker of mine who's quite a C/C++ jockey used it recently (this month), and said it's still very good.
Re:FlexeLint / PC-lint (Score:3, Informative)
A few points, though:
- It is purely text-based, so if you are looking for a shiny GUI-based tool (easier to sell to the PHB), you are out of luck.
- depending on the quality of your code, running it for the first time can result in a huge (make that HUGE) amount of warnings. You might want to start small and only turn on more and more options later. Initially, you will have to invest quite a bit of time to get your code "lint-clean". In the long run, this is well worth it.
What software analysis tool? That all depends... (Score:3, Informative)
One important thing to consider is the set of compilers, tools, target system, and build environments you are using. If you are using MS only products the you will most likely have very good support because most all source code analysis suits will simply import the build information and you will be off and running right away. If your environment is Unix or embedded systems then things may be more difficult because you will need to hook into the build process somehow. The scanner tools usually intercept the CC command from a "make" build and call their back end using their custom processing rather than the compiler proper. Different products do this in different ways so be sure the product you choose knows how to deal with your specific build environment. In my case I walked into another parties environment and needed to simulate a build for a new build environment that I had never seen before, every time. Not one environment ever looked like the next, so the setup and configuration was always a big challenge, just to get started.
Prexis is primarily a tool for life cycle scanning of source code for security issues. There are two ways to perform the code scanning, with either the main engine component which can schedule nightly scans and track progress over time or with the additional Prexis Pro utility, which is designed for quick assessments by the engineers on their own code without logging everything into the main database. The Pro tool worked best for my code assessments since I had no need for tracking changes over time, and it was a little easier to configure which counts for a lot in my situation.
PolySpace is a completely different tool with a different purpose from Prexis. PolySpace attempts to mathematically discover runtime flaws in the code while only using static analysis to do so. It does a great job on smaller projects, but because of the complexity and thoroughness of its analysis, it is somewhat slow. PolySpace needs to evaluate an entire application all at once in order to do a good analysis. If your .5 MSLOC of code is many separate programs/executables then you will be fine, but if you are talking about one huge monolithic application then you may have to evaluate it in chunks which just increases the false positives and forces the engineer to do more manual chasing of details to determine if the issue is really a problem or not. From what I have seen this product is in a class by itself.
BTW - keep you eyes on this site: http://samate.nist.gov/index.php/Main_Page [nist.gov]
Re:My Static Analysis (Score:2, Informative)
Most console computer games for example start at around 500K lines...
Fortify Software has a static tool (Score:2, Informative)