C++有些可能错误修改(cppcheck检查出来的错误)
2016-10-18 08:27
260 查看
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 );
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 );
相关文章推荐
- 基于c++和linux的线程池技术及框架实现(网络下载,测试并修改其中可能的错误)
- 整理磁盘碎片时候,分析出来:驱动器C盘可能已损坏.提示的是:驱动器C盘可能已损坏,要检查并修复驱动器.请运行 chkdsk/f
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C#中可以消除常见且浪费时间的C和C++错误的修改
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- 多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- 说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
- 多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
- C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)