警告 C6388
'argument' 可能不是 'value':这不符合函数 'function-name' 的规范:行:x,y
注解
此警告指示在指定上下文中使用了其他值。 通常,如果将值作为参数传递给了不需要此值的函数,则会报告此警告。
代码分析名称:INVALID_PARAM_VALUE_2
示例
以下代码生成警告 C6388,因为 DoSomething
需要 null 值,但可能传递非 null 值:
// C6388_warning.cpp
#include <string.h>
#include <malloc.h>
#include <sal.h>
void DoSomething( _Pre_ _Null_ void* pReserved );
void f()
{
void* p = malloc( 10 );
DoSomething( p ); // Warning C6388
// code...
free(p);
}
若要更正此警告,请使用以下示例代码:
// C6388_no_warning.cpp
#include <string.h>
#include <malloc.h>
#include <sal.h>
void DoSomething( _Pre_ _Null_ void* pReserved );
void f()
{
void* p = malloc( 10 );
if (!p)
{
DoSomething( p );
}
else
{
// code...
free(p);
}
}
malloc
和 free
的使用在内存泄漏和异常方面有许多缺陷。 为了完全避免此类泄露和异常问题,请使用 C++ 标准库 (STL) 提供的机制。 其中包括 shared_ptr
、unique_ptr
和容器(例如 vector
)。 有关详细信息,请参阅智能指针和 C++ 标准库。