FREfast使用

 

1. 什么是Prefast

Prefast是一种代码分析工具,它能够帮助你找到编译器不能找到的错误或者缺陷。Prefast首次被微软集成到Visual Studio 2005 Team Suite中去,使用起来非常方便。

2.怎么使用Prefast
在vs2005 Team Suite中,使用Prefast非常简单。修改你的工程属性,设置Enable Code Analysis For C/C++为Yes.

prefast1.jpg

效果:
prefast2.jpg

注意到有可能错误的地方以浅灰色显示在编辑器中了。

 

vc6中使用Prefast的方法:

prefast是附带在微软的DDK中的

In VC6 project

1. Install Windows IFS Kit and DDK package
2. Execute Development Kits->Windows IFS Kit and DDK ->Build environment -> windows 2000->windows 2000 checked build environment
3. Export Visual Studio project to a .mak file
4. remove /GZ in .mak file or link fail
5. Edit a run.bat file (not necessary, only for set new include and lib path)

run.bat file content
----------------
rem set include and lib path
set include=C:/Program Files/Microsoft Visual Studio/VC98/atl/include;C:/Program Files/Microsoft Visual Studio/VC98/mfc/include;C:/Program Files/Microsoft Visual Studio/VC98/include
set lib=C:/Program Files/Microsoft Visual Studio/VC98/mfc/lib;C:/Program Files/Microsoft Visual Studio/VC98/lib
rem clean environment
nmake /f httpgetfile.mak clean
rem run prefast command
C:/WINDDK/3790.1830/bin/x86/prefast/scripts/prefast nmake /f httpgetfile.mak CFG="HttpGetFile - Win32 Debug"
rem unset include and lib path
set lib=
set include=

 

3.Prefast能帮你找到哪些错误

1)没有初始化

// no initial
void  defect1()
{
        
int  a;
        
int  b;

        b 
=  a;
}

会报: d:/test/testcode/testcode.cpp(18) : warning C6001: Using uninitialized memory 'a': Lines: 15, 16, 18

2)空指针取值

// one path dereference NULL
void  defect4( int  b,  int  c)
{
        
int   * =  NULL;
        
int  a  =   1 ;

        
if  (b  ==   1 ) {
                
if  (c  ==   1 ) {
                        p 
=   & a;
                }
                
else  {
                                                
                }
        }
        
else  {
                
if  (c  ==   1 ) {

                }
                
else  {
                        p 
=   & a;
                }
        }

        
* p;

        
return ;
}    

会报:d:/test/testcode/testcode.cpp(65) : warning C6011: Dereferencing NULL pointer 'p': Lines: 45, 46, 48, 57, 65

3)可能错误的运算符优先级

void  defect5()
{
        
int  a  =   1 ;
        
int  b  =   1 ;
        
int  c  =   1 ;

        
if  (a  &  b  ==  c)
                
return ;
}

会报: d:/test/testcode/testcode.cpp(76) : warning C6281: Incorrect order of operations: relational operators have higher precedence than bitwise operators

4)可能的buffer overrun

void  defect8()
{
        
char  buf[ 100 ];
        
char  buf2[ 200 ];
        
int  i  =   100 ;

        sprintf(buf, 
" hello world %d " , i);
        strcpy(buf, buf2);
}

会报: d:/test/testcode/testcode.cpp(133) : warning C6202: Buffer overrun for 'buf', which is possibly stack allocated, in call to 'strcpy': length '200' exceeds buffer size '100'

5)可能的无穷循环

// infinite loop
void  defect14()
{
        signed 
char  i;

        
for  (i  =   100 ; i  >=   0 ; i ++ ) {
                ; 
        }
}

会报: d:/test/testcode/testcode.cpp(198) : warning C6292: Ill-defined for-loop: counts up from maximum

6)格式字符串错误

// Format string mismatch
void  defect21()
{
        
char  buff[ 5 ];
        sprintf(buff, 
" %s %s " " a " );
}

会报: d:/test/testcode/testcode.cpp(277) : warning C6063: Missing string argument to 'sprintf' that corresponds to conversion specifier '2'

7)安全问题

void  defect27()
{
        CreateProcess(NULL,
               
" c://program files//Project.exe arg1 " // correct "/"c://program files//Project.exe/" arg1",
               NULL,
               NULL,
               
false ,
               
0 ,
               NULL,
               NULL,
               NULL,
               NULL);               
}

会报: d:/test/testcode/testcode.cpp(327) : warning C6277: NULL application name with an unquoted path in call to 'CreateProcessA': results in a security vulnerability if the path contains spaces

8)=和==误用

void  defect32()
{
        
int  a  =   1 ;

        
if  (a  =   2 )
                
return ;
}

会报: d:/test/testcode/testcode.cpp(405) : warning C6282: Incorrect operator: assignment of constant in Boolean context. Consider using '==' instead

9)逻辑运算问题

// always false
void  defect45()
{
        
int  x;

        
if  ( 0   &&  x ++ ) {
                ;
        }
}

会报: d:/test/testcode/testcode.cpp(564) : warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects

10)其他

【SCI一区论文复】基于SLSPC系列的高阶PT-WPT无线电能传输系统研究(Matlab代码实现)内容概要:本文围绕“基于SLSPC系列的高阶PT-WPT无线电能传输系统研究”展开,重点复现SCI一区论文中的核心技术,通过Matlab代码实现高阶无线电能传输系统的建模与仿真。研究聚焦SLSPC拓扑结构在恒压-恒流(CV/CC)输出特性方面的优势,深入分析系统的传输效率、耦合特性、频率分裂现象及参数敏感性,并探讨其在高功率、长距离无线充电场景中的应用潜力。文中详细给出了系统数学建模、参数设计、仿真验证等关键步骤,旨在帮助读者掌握先进无线电能传输技术的核心原理与实现方法。; 适合人群:具备一定电力电子、自动控制理论基础,熟悉Matlab/Simulink仿真工具,从事无线电能传输、新能源充电技术等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入理解SLSPC型无线电能传输系统的恒压恒流输出机理;②掌握高阶WPT系统的建模、仿真与性能分析方法;③复现SCI一区论文成果,为后续科研创新提供技术基础和代码参考;④应用于无线充电、电动汽车、植入式医疗设备等领域的系统设计与优化。; 阅读建议:建议读者结合Matlab代码逐段分析系统模型构建过程,重点关注谐振参数设计、传输特性仿真及效率优化策略,同时可拓展研究不同耦合条件下的系统行为,以深化对高阶WPT系统动态特性的理解。
(Mathcad+Simulink仿真)基于扩展描述函数法的LLC谐振变换器小信号分析设计内容概要:本文介绍了基于扩展描述函数法(Extended Describing Function Method)对LLC谐振变换器进行小信号建模与分析的设计方法,结合Mathcad数学计算工具与Simulink仿真平台,实现理论推导与系统仿真的有机结合。文章重点阐述了LLC变换器在不同工作模式下的谐波近似建模过程,利用扩展描述函数法提取非线性环节的等效线性化模型,进而构建系统的动态小信号模型,用于频率响应分析与控制器设计。通过Simulink搭建闭环仿真模型验证所建模型的准确性,并借助Mathcad完成复杂的符号运算与参数计算,提升建模效率与设计精度。该方法有效解决了传统小信号模型难以精确描述谐振变换器非线性动态特性的问题,为高频高效电源系统的稳定性分析与优化设计提供了理论支持。; 适合人群:从事电力电子、电源系统设计及相关领域的研究生、科研人员及工程技术人员,具备一定的电路理论、自动控制原理和Matlab/Simulink仿真基础; 使用场景及目标:①掌握LLC谐振变换器的小信号建模方法,特别是非线性系统的线性化处理技巧;②学习扩展描述函数法在电力电子变换器中的应用,提升高频谐振变换器的动态性能分析与控制器设计能力;③结合Mathcad与Simulink实现“理论推导+仿真验证”的一体化研究流程; 阅读建议:建议读者结合文中Mathcad公式推导与Simulink仿真模型同步实践,重点关注扩展描述函数的构建过程与关键参数的敏感性分析,深入理解谐振变换器在不同负载条件下的动态特性变化规律。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值