The C + + static code analysis tool PREfast in VS 2008

Source: Internet
Author: User

Author: Zhu Jinchan
Source: http://blog.csdn.net/clever101/


I learned from the Shing Cloud blog that the team version of Visual Studio 2005/2008 integrates a C + + Static code analysis tool PREfast, specially tested, really good.


The specific usage is illustrated in the following example:

1. Build a console project, typing the following code:


int F (bool b) {int i; if (b) {i = 0;} return i;///when B is false, variable I uninitialized}


2. Open Project Properties--> Configuration Properties--> Code Analysis-->enable Code Analysis 。 Select Yes (/analyze). The following figure:




If you use the CL.exe command-line compiler directly, use the/analyze compilation option. For example: Cl Test.cpp-w4/ehsc/analyze.


3. When compiling the project, the following warning appears:

1>f:/mytest/mytest/src/testsort/testsort.cpp (km): Warning c6001:using uninitialized memory ' I ': lines:29, 31, 39

4. Do not assume that this is a warning provided by the compiler, click on this warning you will find the clue, the original is PREfast prompted you: When B is false, the variable I uninitialized, where the lines:29, 31, 39 is prompted by the code of these lines led to this warning, specifically the following figure:




Reference documents:


1. Safe Coding Practice Three: C/prefast Static code analysis tool, author: Shing Cloud















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.