C++有些可能错误修改(cppcheck检查出来的错误)

1.父类子类都有同类型同名变量,子类的可以去掉;

2.Assert statement calls a function which may have desired side effects: 'type'. assert(token->type()==TOKEN_CAMERA);

3.无符号整形打印用%u, 

整数int类型用%d

long用%ld

unsigned long用%lu

而size_t在C99标准用%zu,在vs2008——2013用%Iu,在vs2015又支持%Iu。

打印:unsigned long为%lu, unsigned int为%u, C99标准size_t为%zu.

fprintf(f,"level%d has %lu dance\n",i,danceitem_bylev[i].size());


 in format string (no. 2) requires 'int' but the argument type is 'size_t {aka unsigned long}',代码中此处改为%Iu,由于环境是vs2008.

4.DWORD实际上是unsigned int。

5.H3DVec3 leftDown(aabb[0], aabb[1], aabb[2]);可能存在空指针,

修改:

if(aabb==NULL)
return;
H3DVec3 leftDown(aabb[0], aabb[1], aabb[2]);

6.f = fopen("action_move_list.txt","w");

加上fclose(f);

7.CreateThread(NULL,0,p,(LPVOID)this,0,0);返回值可能没被用到,解决:

HANDLE hThread = CreateThread(NULL,0,p,(LPVOID)this,0,0);

if(hThread==NULL)
{
msg("Create PLAYING Thread failed");
        return false; 

}

m_handle = h_Thead;


头文件定义HANDLE m_handle;

构造函数初始化m_handle = NULL;

析构函数if(m_handle)

{

WaitForSingleObject(m_handle, INFINITE);

CloseHandle(m_handle);

}


9.for(std::vector<CTokenRyth*>::const_iterator it=tokenlist.begin();it!=tokenlist.end();++it) 这里it用前缀比后缀好

10.if (sel.choiceList.size())
{

}改为

    if(!sel.choiceList.empty())

{}

11.string类型不需要初始化。

12.CToken* token  = *it;
token = NULL;
delete token;

第一个赋值还没用,就被重复赋值。改为:

CToken* token  = *it;
delete token;
token = NULL;

DWORD ret = pfnMiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
file,
MiniDumpNormal,
//MiniDumpFilterMemory,
&eInfo,
NULL,
NULL );

ret = CloseHandle( file );


可以改为

//DWORD ret = pfnMiniDumpWriteDump(
// GetCurrentProcess(),
// GetCurrentProcessId(),
// file,
// MiniDumpNormal,
// //MiniDumpFilterMemory,
// &eInfo,
// NULL,
// NULL );

DWORD ret = CloseHandle( file );

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值