1

分析器报告某个参数未初始化。我不明白为什么。

编码:

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');

分析仪投诉是:

  1. “缓冲区”未初始化
  2. 使用了“缓冲区”,但可能尚未初始化

现在,根据此函数的 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 
);

也许我错过了“何时”的事情?

4

1 回答 1

0

我认为您需要检查dataTypeREG_SZ(或REG_MULTI_SZ如有必要)。

'when' 子句说“如果dataType是 REG_SZ,那么buffer将被初始化”......但分析器不知道它不是存储在其中的 REG_DWORD reqSize(是的,知道那不是函数存储 REG_DWORD,但分析器不存储)。

于 2016-01-04T12:25:15.717 回答