setupapi: Avoid unnecessary buffer allocation in SetupDiCreateDeviceInfoA().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-11-27 19:55:35 -06:00 committed by Alexandre Julliard
parent 8289c651c0
commit ad5314040b
1 changed files with 3 additions and 8 deletions

View File

@ -1341,8 +1341,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name,
const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags, const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags,
PSP_DEVINFO_DATA DeviceInfoData) PSP_DEVINFO_DATA DeviceInfoData)
{ {
WCHAR nameW[MAX_DEVICE_ID_LEN];
BOOL ret = FALSE; BOOL ret = FALSE;
LPWSTR DeviceNameW = NULL;
LPWSTR DeviceDescriptionW = NULL; LPWSTR DeviceDescriptionW = NULL;
if (!name || strlen(name) >= MAX_DEVICE_ID_LEN) if (!name || strlen(name) >= MAX_DEVICE_ID_LEN)
@ -1351,23 +1351,18 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name,
return FALSE; return FALSE;
} }
DeviceNameW = MultiByteToUnicode(name, CP_ACP); MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, sizeof(nameW));
if (DeviceNameW == NULL) return FALSE;
if (DeviceDescription) if (DeviceDescription)
{ {
DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP); DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
if (DeviceDescriptionW == NULL) if (DeviceDescriptionW == NULL)
{
MyFree(DeviceNameW);
return FALSE; return FALSE;
} }
}
ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW, ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, nameW, ClassGuid, DeviceDescriptionW,
hwndParent, CreationFlags, DeviceInfoData); hwndParent, CreationFlags, DeviceInfoData);
MyFree(DeviceNameW);
MyFree(DeviceDescriptionW); MyFree(DeviceDescriptionW);
return ret; return ret;