无法理解VS2015分析仪报告
Can't understand VS2015 Analyzer report
分析器报告某个参数未初始化。我不明白为什么。
代码:
LPTSTR buffer = NULL;
DWORD reqSize = 16000;
DWORD dataType;
LPTSTR * array;
DWORD szChars;
BOOL bRegProp;
// Allocate buffer according to required size
buffer = new TCHAR[(reqSize /sizeof(TCHAR))+2];
if(!buffer)
return NULL;
// Get the string into the buffer
if (FALSE == SetupDiGetDeviceRegistryProperty(Devs, DevInfo, Prop, &dataType, (LPBYTE)buffer, reqSize, &reqSize))
return NULL;
szChars = reqSize/sizeof(TCHAR);
buffer[szChars] = TEXT(' ');
分析仪投诉有:
- "buffer"未初始化
- 已使用"buffer",但可能尚未初始化
现在,根据这个函数的SAL注释,您需要确保它不会返回false:
_Success_(return != FALSE)
_When_((*PropertyRegDataType == REG_SZ), _At_((PSTR) PropertyBuffer, _Post_valid_))
_When_((*PropertyRegDataType == REG_MULTI_SZ), _At_((PZZSTR) PropertyBuffer, _Post_valid_))
WINSETUPAPI
BOOL
WINAPI
SetupDiGetDeviceRegistryPropertyA(
_In_ HDEVINFO DeviceInfoSet,
_In_ PSP_DEVINFO_DATA DeviceInfoData,
_In_ DWORD Property,
_Out_opt_ PDWORD PropertyRegDataType,
_Out_writes_bytes_to_opt_(PropertyBufferSize, *RequiredSize) PBYTE PropertyBuffer,
_In_ DWORD PropertyBufferSize,
_Out_opt_ PDWORD RequiredSize
);
也许我错过了"何时"这件事?
我认为您需要检查dataType
是否为REG_SZ
(如有必要,请检查REG_MULTI_SZ
)。
"when"子句表示"如果dataType
是REG_SZ,则buffer
将已初始化"。。。但是分析器不知道它不是存储在reqSize
中的REG_DWORD(是的,I知道这不是函数存储REG_DWORDs的地方,但分析器不知道)。
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- 使用std::source_location报告错误的最佳实践
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 当用户超过按钮点击限制时报告
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么cudaMemGetInfo报告设备内存总量的变化
- 为什么瓦尔格林德在不释放恶意内存后没有报告任何问题?
- 内存清理程序报告全局对象构造中未初始化值的使用
- QDataStream 读取和写入的字节数比 QFile::length() 报告要多
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- Valgrind 在 std::string::swap 中报告 SIGILL
- DRD 报告"conflicting load" std::mutex::lock 上的错误
- 柯南,CMake.test()生成XML报告
- 如何构建一个异常类来报告C++中的哪些文件和行号?
- Valgrind 在 QThread::start() 上报告内存泄漏
- 我是否访问了已释放的内存,或者在这种情况下DrMemory报告不正确?
- 瓦尔格林德报告在 =带有嵌套shared_ptrs的运算符上的读取错误
- 为什么 valgrind 报告两个内存分配,而我的代码只请求一个?
- 无法理解VS2015分析仪报告