分析器报告某个参数未初始化。我不明白为什么。
编码:
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('\0');
分析仪投诉是:
- “缓冲区”未初始化
- 使用了“缓冲区”,但可能尚未初始化
现在,根据此函数的 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
);
也许我错过了“何时”的事情?