cppcheck 静态代码测试

参考:https://blog.csdn.net/jiang1986829/article/details/51328830

S1:下载源码

https://sourceforge.net/projects/cppcheck/files/cppcheck/

S2:编译源码

进入源码目录

pwd(记下源码路径)

make CFGDIR=(源码路径)/cfg/ 

make install (或者sudo make install)
S3:设置环境变量

sudo vim /etc/profile,在最后添加如下

CPPCHECK_HOME=(cpp_check源码目录)
PATH=${PATH}:${CPPCHECK_HOME}
CLASSPATH=${CLASSPATH}:${CPPCHECK_HOME}
 

使用方法

在源码路径

cppcheck --enable=all --xml --xml-version=2 ./ 2>report.xml (最后的2>report.xml不能有空格)

然后将报告可视化

cppcheck-htmlreport --file=./report.xml --report-dir=./report --source-dir=./

这样将在当前路径下生成report目录,并将报告放进去

展开阅读全文

代码测试?

04-14

//---------------------------------------------------------------------------rnrn#include rn#include rn#include rn#include rnrn#pragma hdrstoprnrn#include "Unit1.h"rn//---------------------------------------------------------------------------rn#pragma package(smart_init)rn#pragma resource "*.dfm"rnTForm1 *Form1;rn//---------------------------------------------------------------------------rn__fastcall TForm1::TForm1(TComponent* Owner)rn : TForm(Owner)rnrnrn//---------------------------------------------------------------------------rnrnvoid __fastcall TForm1::btn1Click(TObject *Sender)rnrn PUSER_INFO_3 pUsr = NULL;rn NET_API_STATUS netRet = 0;rn DWORD dwParmError = 0;rnrn wchar_t temp[5][200];rn pUsr->usri3_name =StringToWideChar("yy", temp[0], 200); //yy是用户名rnrnnetRet = NetUserGetInfo( NULL, pUsr->usri3_name, 3, (LPBYTE *)&pUsr);rn if( netRet == NERR_Success )rn rnrnpUsr->usri3_password_expired = TRUE;rnnetRet = NetUserSetInfo( NULL, pUsr->usri3_name, 3, (LPBYTE)pUsr, &dwParmError);rnrnif( netRet == NERR_Success )rn printf("User %S will need to change password at next logon", pUsr->usri3_name);rnelse printf("Error %d occurred. Parm Error %d returned.\n", netRet, dwParmError);rnrnNetApiBufferFree( pUsr);rnrnelse rnprintf("NetUserGetInfo failed: %d\n",netRet);rnrnrn//---------------------------------------------------------------------------rnrn其效果是要达到"提示用户第一次登录时修改密码".rnrnrn该代码出自rnhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/forcing_a_user_to_change_the_logon_password.asprnrn该代码可以编译通过,但是无法运行????????????????????????rn 论坛

没有更多推荐了,返回首页