Commit ad531404 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

setupapi: Avoid unnecessary buffer allocation in SetupDiCreateDeviceInfoA().

parent 8289c651
...@@ -1341,8 +1341,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name, ...@@ -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, ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment