PREfast is a static analysis tool that identifies defects in C/C++ programs. It uses your existing build structure and works by intercepting your native compiler. Intra-procedural analysis identifies defects in the C/C++ source files.
Users commonly run PREfast over a section of code, view results, make fixes, and then run PREfast again. It is recommended that you divide your build into small (10 MB or less) sections, and run PREfast on each section.
PREfast displays a log of the code defects encountered. Each line entry in the log shows a description of the type of defect, a PREfast warning number, the source location, and function where the defect occurred.
The following defect message indicates that PREfast warning 501 occurred in function main, where PREfast found an HRESULT cast to a BOOL at line 21 of the source program test1.cpp.
Casting HRESULT to BOOL 501 c:\prefast\test\test1.cpp(21) main
To execute PREfast, use whatever build command you normally use at the command line, prefaced by the word prefast. Follow the build command with command-specific arguments, as shown in the following command:
prefast
PREfast recognizes three standard build commands:
Compiles and runs PREfast on an individual file and prints the PREfast results textually.
E.g. prefast cl /c test.c
Performs an Nmake and runs PREfast on all compiled files and prints the PREfast results textually. Any nmake-arguments are passed as arguments to Nmake.
E.g. prefast nmake /f pfw_build.mak
Performs an Nmake and runs PREfast on all compiled files and prints the PREfast results textually. Any build-arguments are passed as arguments to build.
E.g. prefast build /cefZ
You can use one of four PREfast-specific commands to customize PREfast:
HELP
| Opens the PREfast user guide.
|
LIST
| Writes the defect log to the console.
|
RESET
| Removes all existing defects from the defect log.
|
VIEW
| Displays the user interface for the PREfast defect log.
|