C ++中SecureZeroMemory中的参数不匹配

时间:2014-09-26 06:49:22

标签: visual-c++

char *chBuff = new char[nBufferSize];
    ::SecureZeroMemory(chBuff, sizeof(chBuff));

我使用了上面的代码但得到以下错误

Wrong sizeof argument (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument chBuff of type char * and argument 4UL /* sizeof (chBuff) */ to function RtlSecureZeroMemory is suspicious.

我应该进行类型转换吗?如果是这样的话?

SecureZeroMemory的语法:

PVOID SecureZeroMemory(
  _In_  PVOID ptr,
  _In_  SIZE_T cnt
);

1 个答案:

答案 0 :(得分:0)

sizeof(char *)将为您提供指针的大小,而不是使用以下内容:

char *chBuff = new char[nBufferSize];
    ::SecureZeroMemory(chBuff, sizeof(char)*nBufferSize);