Slashdot Mirror


Static Code Analysis Tools?

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?"

13 of 87 comments (clear)

  1. Prodev Workshop by dwater · · Score: 3, Informative

    I found the static analyser in SGI's Prodev Workshop to be quite excellent, though that was a while ago and I am comparing it with nothing - I'm not sure how it stacks up against more recent offerings :

    http://www.sgi.com/products/software/irix/tools/pr odev.html#B

    Looks like it's IRIX only though, so YMMV, to put it mildly.

    --
    Max.
  2. LLVM by klahnako · · Score: 2, Informative

    I just started looking at LLVM, maybe it is good for what you want.

    http://llvm.org/

  3. PreFast by Yakust · · Score: 2, Informative

    If you are on Windows, you can use the native C++ static analysis that comes with the Windows SDK.
    Just add the /analyze switch when invoking the compiler (cl.exe)
    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.

  4. Re:FindBugs by Anonymous Coward · · Score: 2, Informative

    But FindBugs does not cover the C/C++ codebase...

    C/C++ checkers:
      http://www.coverity.com/ (commercial)
      http://www.dwheeler.com/flawfinder/ (OSS)

  5. Coverity by LLuthor · · Score: 4, Informative

    I strongly suggest you look at coverity.

    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.

    --
    LL
  6. FlexeLint / PC-lint by DoofusOfDeath · · Score: 4, Informative

    http://www.gimpel.com/html/lintinfo.htm/

    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.

    1. Re:FlexeLint / PC-lint by JDisk · · Score: 2, Informative

      I have to agree with this recommendation (Gimpel lint).

      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.

  7. Careful what you wish for by pdovy · · Score: 2, Informative

    Whatever you use, make sure you adjust the settings to only capture those problems that you think are critical. With 500k lines of code, unless your codebase is *extremely* solid running a Lint tool will result in a LOT of action items. I've used SPLINT (a lint for secure programming - http://www.splint.org/) in a project with a codebase much smaller than 500k and it took weeks to finish addressing all the issues - sometimes these things can be more of a curse than a blessing.

  8. C and C++ Static Analysis tools by tjwhaynes · · Score: 2, 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 and also with the output from Reasoning. 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, an updated successor.

    Also well worth investigating to see how your code is actually running is Valgrind and it's associated tools. 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

    --
    Anything I post is strictly my own thoughts and doesn't necessarily have anything to do with the opinions of IBM.
  9. Purify by Khelder · · Score: 2, Informative
    I'm happy to say I used C/C++ heavily for quite a while now, but when I did, Purify was really, really useful for finding problems.

    A coworker of mine who's quite a C/C++ jockey used it recently (this month), and said it's still very good.

  10. What software analysis tool? That all depends... by hAckz0r · · Score: 3, Informative
    There are many software tools out there for static analysis, but differ in what they do or who they target as their customer. The big names in my mind are Coverty, Fortify, Prexis, and PolySpace. I only have personal experience with Prexis and PolySpace so I will just speak to those.


    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

  11. Re:My Static Analysis by idries · · Score: 2, Informative

    Many sucessful products are made up of around 500K lines of C++.

    Most console computer games for example start at around 500K lines...

  12. Fortify Software has a static tool by robby_r · · Score: 2, Informative

    Fortify a security static scanner and covers C/C++ as well as Java, JSP, .NET, C#, XML, CFML, PL/SQL and T-SQL.