tags:

views:

172

answers:

2

Is there a way to get FxCop to analyze unmanaged C++ code? Setting the /clr flag allowed FxCop to open the .exe. It find a LOT of C++ items, but the analysis on the code is very weak. For example, the following code was skipped:


int i=0;
if (i=2) printf("Don't worry..everything will be okay.");

I would like a tool that can catch the i=2 and warn that it should be i==2. Any advice on either getting FxCop to be more thorough or another tool that others found useful?

+2  A: 

MSVC (at least VC9/VS2008) already warns about your specific example:

warning C4706: assignment within conditional expression

(Oops: I just realized that I have my test projects settings cranked up to Warning level 4 - /W4. MSVC doesn't issue this warning at the default setting). So set the project settings to /W4 and get more diagnostics (hopefully without too much noise).

I find the warnings in VC9 to be pretty decent, and you can easily set the compiler to treat them as errors if you want to force the issue.

The Team Server edition of Visual Studio contains support for PREfast - a static analysis tool from Microsoft (the option is in the C++ project's Advanced/Enable Code Analysis For C/C++). You can also get the tool in the Windows Driver Kit and/or the Windows SDK, though I can't vouch for the instructions on getting the WDK/SDK version integrated into Visual Studio:

Another alternative some people like (non-free) is Gimpel's PC-Lint product.

Michael Burr
A: 

we use coverity, not free but an awesome static analysis tool

pm100