-- v2: setupapi: Use MultiByteToUnicode and UnicodeToMultiByte instead of reimplementing them. setupapi: Handle NULL in string allocation functions and add tests.
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/setupapi/misc.c | 9 +++++++++ dlls/setupapi/setupapi.spec | 3 +++ dlls/setupapi/tests/misc.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+)
diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index f9d34b5353d..82f2bc2ff0c 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -135,6 +135,9 @@ LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc) { LPWSTR lpDst;
+ if (!lpSrc) + return NULL; + lpDst = MyMalloc((lstrlenW(lpSrc) + 1) * sizeof(WCHAR)); if (lpDst == NULL) return NULL; @@ -236,6 +239,9 @@ LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage) LPWSTR lpUnicodeStr; int nLength;
+ if (!lpMultiByteStr) + return NULL; + nLength = MultiByteToWideChar(uCodePage, 0, lpMultiByteStr, -1, NULL, 0); if (nLength == 0) @@ -277,6 +283,9 @@ LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage) LPSTR lpMultiByteStr; int nLength;
+ if (!lpUnicodeStr) + return NULL; + nLength = WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1, NULL, 0, NULL, NULL); if (nLength == 0) diff --git a/dlls/setupapi/setupapi.spec b/dlls/setupapi/setupapi.spec index 7578fb25c9c..7cb25945ccf 100644 --- a/dlls/setupapi/setupapi.spec +++ b/dlls/setupapi/setupapi.spec @@ -572,6 +572,7 @@ @ stub pSetupAppendStringToMultiSz @ stub pSetupDestroyRunOnceNodeList @ stub pSetupDirectoryIdToPath +@ stdcall pSetupDuplicateString(ptr) DuplicateString @ stdcall pSetupFree(ptr) MyFree @ stdcall pSetupGetField(ptr long) @ stdcall pSetupGetGlobalFlags() @@ -584,6 +585,7 @@ @ stdcall pSetupIsUserAdmin() IsUserAdmin @ stub pSetupMakeSurePathExists @ stdcall pSetupMalloc(long) MyMalloc +@ stdcall pSetupMultiByteToUnicode(str long) MultiByteToUnicode @ stdcall pSetupRealloc(ptr long) MyRealloc @ stdcall pSetupSetGlobalFlags(long) @ stdcall pSetupSetQueueFlags(ptr long) @@ -600,5 +602,6 @@ @ stdcall pSetupStringTableLookUpString(ptr wstr long) StringTableLookUpString @ stdcall pSetupStringTableLookUpStringEx(ptr wstr long ptr ptr) StringTableLookUpStringEx @ stdcall pSetupStringTableSetExtraData(ptr long ptr long) StringTableSetExtraData +@ stdcall pSetupUnicodeToMultiByte(wstr long) UnicodeToMultiByte @ stub pSetupVerifyCatalogFile @ stub pSetupVerifyQueuedCatalogs diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c index b9eb3e6c75f..d724f0c92f1 100644 --- a/dlls/setupapi/tests/misc.c +++ b/dlls/setupapi/tests/misc.c @@ -47,9 +47,12 @@ static CHAR CURR_DIR[MAX_PATH]; * - copy styles */
+static WCHAR* (WINAPI *pDuplicateString)(const WCHAR*); static void (WINAPI *pMyFree)(void*); +static WCHAR* (WINAPI *pMultiByteToUnicode)(const char*, UINT); static BOOL (WINAPI *pSetupGetFileCompressionInfoExA)(PCSTR, PSTR, DWORD, PDWORD, PDWORD, PDWORD, PUINT); static BOOL (WINAPI *pSetupQueryInfOriginalFileInformationA)(PSP_INF_INFORMATION, UINT, PSP_ALTPLATFORM_INFO, PSP_ORIGINAL_FILE_INFO_A); +static char* (WINAPI *pUnicodeToMultiByte)(const WCHAR*, UINT);
static void create_file(const char *name, const char *data) { @@ -904,6 +907,32 @@ static void test_device_interfaces(void) SetupDiDestroyDeviceInfoList(devinfo); }
+static void test_string_functions(void) +{ + static const char srcA[] = "Hello world!"; + static const WCHAR srcW[] = L"Hello world!"; + char *dstA; + WCHAR *dstW; + + ok(pDuplicateString(NULL) == NULL, "Expected NULL\n"); + ok(!!(dstW = pDuplicateString(srcW)), "Expected non-NULL\n"); + ok(dstW != srcW, "Expected dstA != srcA\n"); + ok(wcscmp(srcW, dstW) == 0, "Expected 0\n"); + pMyFree(dstW); + + if (0) ok(pMultiByteToUnicode(NULL, CP_ACP) == NULL, "Expected NULL\n"); /* crashes on win10 */ + ok(!!(dstW = pMultiByteToUnicode(srcA, CP_ACP)), "Expected non-NULL\n"); + ok(wcscmp(srcW, dstW) == 0, "Expected 0\n"); + pMyFree(dstW); + + if (0) ok(pUnicodeToMultiByte(NULL, CP_ACP) == NULL, "Expected NULL\n"); /* crashes on win10 */ + ok(!!(dstA = pUnicodeToMultiByte(srcW, CP_ACP)), "Expected non-NULL\n"); + ok(strcmp(srcA, dstA) == 0, "Expected 0\n"); + pMyFree(dstA); + + pMyFree(NULL); /* should not crash */ +} + START_TEST(misc) { HMODULE hsetupapi = GetModuleHandleA("setupapi.dll"); @@ -911,6 +940,9 @@ START_TEST(misc) pMyFree = (void*)GetProcAddress(hsetupapi, "MyFree"); pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA"); pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA"); + pDuplicateString = (void*)GetProcAddress(hsetupapi, "pSetupDuplicateString"); + pMultiByteToUnicode = (void*)GetProcAddress(hsetupapi, "pSetupMultiByteToUnicode"); + pUnicodeToMultiByte = (void*)GetProcAddress(hsetupapi, "pSetupUnicodeToMultiByte");
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
@@ -928,4 +960,5 @@ START_TEST(misc) test_SetupLogError(); test_CM_Get_Version(); test_device_interfaces(); + test_string_functions(); }
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/setupapi/devinst.c | 8 +-- dlls/setupapi/dialog.c | 20 +++--- dlls/setupapi/misc.c | 12 ++-- dlls/setupapi/query.c | 8 +-- dlls/setupapi/queue.c | 106 +++++++++++++++---------------- dlls/setupapi/setupapi_private.h | 25 +------- 6 files changed, 78 insertions(+), 101 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index ef7b4dccf0d..13dfe092360 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -3738,9 +3738,9 @@ static BOOL call_coinstallers(WCHAR *list, DI_FUNCTION function, HDEVINFO devinf { if (procnameW) { - procname = strdupWtoA(procnameW + 1); + procname = UnicodeToMultiByte(procnameW + 1, CP_ACP); coinst_proc = (void *)GetProcAddress(module, procname); - heap_free(procname); + MyFree(procname); } else coinst_proc = (void *)GetProcAddress(module, "CoDeviceInstall"); @@ -3837,9 +3837,9 @@ BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION function, HDEVINFO devinfo, SP { if (procnameW) { - procname = strdupWtoA(procnameW + 1); + procname = UnicodeToMultiByte(procnameW + 1, CP_ACP); classinst_proc = (void *)GetProcAddress(module, procname); - heap_free(procname); + MyFree(procname); } else classinst_proc = (void *)GetProcAddress(module, "ClassInstall"); diff --git a/dlls/setupapi/dialog.c b/dlls/setupapi/dialog.c index 5a0eadcb760..f0eec3833b6 100644 --- a/dlls/setupapi/dialog.c +++ b/dlls/setupapi/dialog.c @@ -192,20 +192,20 @@ UINT WINAPI SetupPromptForDiskA(HWND hwndParent, PCSTR DialogTitle, PCSTR DiskNa debugstr_a(TagFile), DiskPromptStyle, PathBuffer, PathBufferSize, PathRequiredSize);
- DialogTitleW = strdupAtoW(DialogTitle); - DiskNameW = strdupAtoW(DiskName); - PathToSourceW = strdupAtoW(PathToSource); - FileSoughtW = strdupAtoW(FileSought); - TagFileW = strdupAtoW(TagFile); + DialogTitleW = MultiByteToUnicode(DialogTitle, CP_ACP); + DiskNameW = MultiByteToUnicode(DiskName, CP_ACP); + PathToSourceW = MultiByteToUnicode(PathToSource, CP_ACP); + FileSoughtW = MultiByteToUnicode(FileSought, CP_ACP); + TagFileW = MultiByteToUnicode(TagFile, CP_ACP);
ret = SetupPromptForDiskW(hwndParent, DialogTitleW, DiskNameW, PathToSourceW, FileSoughtW, TagFileW, DiskPromptStyle, PathBufferW, MAX_PATH, PathRequiredSize);
- HeapFree(GetProcessHeap(), 0, DialogTitleW); - HeapFree(GetProcessHeap(), 0, DiskNameW); - HeapFree(GetProcessHeap(), 0, PathToSourceW); - HeapFree(GetProcessHeap(), 0, FileSoughtW); - HeapFree(GetProcessHeap(), 0, TagFileW); + MyFree(DialogTitleW); + MyFree(DiskNameW); + MyFree(PathToSourceW); + MyFree(FileSoughtW); + MyFree(TagFileW);
if(ret == DPROMPT_SUCCESS) { diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index 82f2bc2ff0c..36251b598f7 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -857,8 +857,8 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location, media_type, style, dest, buffer_size, required_size, component);
if (dest && !(destW = MyMalloc( buffer_size * sizeof(WCHAR) ))) return FALSE; - if (source && !(sourceW = strdupAtoW( source ))) goto done; - if (location && !(locationW = strdupAtoW( location ))) goto done; + if (source && !(sourceW = MultiByteToUnicode( source, CP_ACP ))) goto done; + if (location && !(locationW = MultiByteToUnicode( location, CP_ACP ))) goto done;
ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW, buffer_size, &size, NULL );
@@ -877,8 +877,8 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location,
done: MyFree( destW ); - HeapFree( GetProcessHeap(), 0, sourceW ); - HeapFree( GetProcessHeap(), 0, locationW ); + MyFree( sourceW ); + MyFree( locationW ); if (ret) SetLastError(ERROR_SUCCESS); return ret; } @@ -1124,9 +1124,9 @@ BOOL WINAPI SetupUninstallOEMInfA( PCSTR inf_file, DWORD flags, PVOID reserved )
TRACE("%s, 0x%08lx, %p\n", debugstr_a(inf_file), flags, reserved);
- if (inf_file && !(inf_fileW = strdupAtoW( inf_file ))) return FALSE; + if (inf_file && !(inf_fileW = MultiByteToUnicode( inf_file, CP_ACP ))) return FALSE; ret = SetupUninstallOEMInfW( inf_fileW, flags, reserved ); - HeapFree( GetProcessHeap(), 0, inf_fileW ); + MyFree( inf_fileW ); return ret; }
diff --git a/dlls/setupapi/query.c b/dlls/setupapi/query.c index e662b422a06..29094272d80 100644 --- a/dlls/setupapi/query.c +++ b/dlls/setupapi/query.c @@ -336,7 +336,7 @@ BOOL WINAPI SetupGetSourceFileLocationA( HINF hinf, PINFCONTEXT context, PCSTR f TRACE("%p, %p, %s, %p, %p, 0x%08lx, %p\n", hinf, context, debugstr_a(filename), source_id, buffer, buffer_size, required_size);
- if (filename && *filename && !(filenameW = strdupAtoW( filename ))) + if (filename && *filename && !(filenameW = MultiByteToUnicode( filename, CP_ACP ))) return FALSE;
if (!SetupGetSourceFileLocationW( hinf, context, filenameW, source_id, NULL, 0, &required )) @@ -364,7 +364,7 @@ BOOL WINAPI SetupGetSourceFileLocationA( HINF hinf, PINFCONTEXT context, PCSTR f ret = TRUE;
done: - HeapFree( GetProcessHeap(), 0, filenameW ); + MyFree( filenameW ); HeapFree( GetProcessHeap(), 0, bufferW ); return ret; } @@ -548,7 +548,7 @@ BOOL WINAPI SetupGetTargetPathA( HINF hinf, PINFCONTEXT context, PCSTR section, TRACE("%p, %p, %s, %p, 0x%08lx, %p\n", hinf, context, debugstr_a(section), buffer, buffer_size, required_size);
- if (section && !(sectionW = strdupAtoW( section ))) + if (section && !(sectionW = MultiByteToUnicode( section, CP_ACP ))) return FALSE;
if (!SetupGetTargetPathW( hinf, context, sectionW, NULL, 0, &required )) @@ -576,7 +576,7 @@ BOOL WINAPI SetupGetTargetPathA( HINF hinf, PINFCONTEXT context, PCSTR section, ret = TRUE;
done: - HeapFree( GetProcessHeap(), 0, sectionW ); + MyFree( sectionW ); HeapFree( GetProcessHeap(), 0, bufferW ); return ret; } diff --git a/dlls/setupapi/queue.c b/dlls/setupapi/queue.c index f6c83d30e1d..7fb13eddf97 100644 --- a/dlls/setupapi/queue.c +++ b/dlls/setupapi/queue.c @@ -105,10 +105,10 @@ static void free_file_op_queue( struct file_op_queue *queue )
while( op ) { - HeapFree( GetProcessHeap(), 0, op->src_path ); - HeapFree( GetProcessHeap(), 0, op->src_file ); - HeapFree( GetProcessHeap(), 0, op->dst_path ); - if (op->dst_file != op->src_file) HeapFree( GetProcessHeap(), 0, op->dst_file ); + MyFree( op->src_path ); + MyFree( op->src_file ); + MyFree( op->dst_path ); + if (op->dst_file != op->src_file) MyFree( op->dst_file ); t = op; op = op->next; HeapFree( GetProcessHeap(), 0, t ); @@ -217,14 +217,14 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, FILEPATHS_W *pathsW = (FILEPATHS_W *)param1; FILEPATHS_A pathsA;
- pathsA.Source = strdupWtoA( pathsW->Source ); - pathsA.Target = strdupWtoA( pathsW->Target ); + pathsA.Source = UnicodeToMultiByte( pathsW->Source, CP_ACP ); + pathsA.Target = UnicodeToMultiByte( pathsW->Target, CP_ACP ); pathsA.Win32Error = pathsW->Win32Error; pathsA.Flags = pathsW->Flags; ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification, (UINT_PTR)&pathsA, param2 ); - HeapFree( GetProcessHeap(), 0, (void *)pathsA.Source ); - HeapFree( GetProcessHeap(), 0, (void *)pathsA.Target ); + MyFree( (void *)pathsA.Source ); + MyFree( (void *)pathsA.Target ); } if (notification == SPFILENOTIFY_COPYERROR) MultiByteToWideChar( CP_ACP, 0, buffer, -1, (WCHAR *)old_param2, MAX_PATH ); @@ -237,23 +237,23 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, SP_REGISTER_CONTROL_STATUSA statusA;
statusA.cbSize = sizeof(statusA); - statusA.FileName = strdupWtoA( statusW->FileName ); + statusA.FileName = UnicodeToMultiByte( statusW->FileName, CP_ACP ); statusA.Win32Error = statusW->Win32Error; statusA.FailureCode = statusW->FailureCode; ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification, (UINT_PTR)&statusA, param2 ); - HeapFree( GetProcessHeap(), 0, (LPSTR)statusA.FileName ); + MyFree( (char*)statusA.FileName ); } break;
case SPFILENOTIFY_QUEUESCAN: { LPWSTR targetW = (LPWSTR)param1; - LPSTR target = strdupWtoA( targetW ); + char *target = UnicodeToMultiByte( targetW, CP_ACP );
ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification, (UINT_PTR)target, param2 ); - HeapFree( GetProcessHeap(), 0, target ); + MyFree( target ); } break;
@@ -263,10 +263,10 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, char path[MAX_PATH]; SOURCE_MEDIA_A mediaA;
- mediaA.Tagfile = strdupWtoA(mediaW->Tagfile); - mediaA.Description = strdupWtoA(mediaW->Description); - mediaA.SourcePath = strdupWtoA(mediaW->SourcePath); - mediaA.SourceFile = strdupWtoA(mediaW->SourceFile); + mediaA.Tagfile = UnicodeToMultiByte(mediaW->Tagfile, CP_ACP); + mediaA.Description = UnicodeToMultiByte(mediaW->Description, CP_ACP); + mediaA.SourcePath = UnicodeToMultiByte(mediaW->SourcePath, CP_ACP); + mediaA.SourceFile = UnicodeToMultiByte(mediaW->SourceFile, CP_ACP); mediaA.Flags = mediaW->Flags; path[0] = 0;
@@ -274,10 +274,10 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification, (UINT_PTR)&mediaA, (UINT_PTR)&path); MultiByteToWideChar(CP_ACP, 0, path, -1, (WCHAR *)param2, MAX_PATH);
- heap_free((char *)mediaA.Tagfile); - heap_free((char *)mediaA.Description); - heap_free((char *)mediaA.SourcePath); - heap_free((char *)mediaA.SourceFile); + MyFree((char *)mediaA.Tagfile); + MyFree((char *)mediaA.Description); + MyFree((char *)mediaA.SourcePath); + MyFree((char *)mediaA.SourceFile); break; } case SPFILENOTIFY_STARTQUEUE: @@ -478,27 +478,27 @@ BOOL WINAPI SetupQueueCopyIndirectA( SP_FILE_COPY_PARAMS_A *paramsA )
paramsW.cbSize = sizeof(paramsW); paramsW.QueueHandle = paramsA->QueueHandle; - paramsW.SourceRootPath = strdupAtoW( paramsA->SourceRootPath ); - paramsW.SourcePath = strdupAtoW( paramsA->SourcePath ); - paramsW.SourceFilename = strdupAtoW( paramsA->SourceFilename ); - paramsW.SourceDescription = strdupAtoW( paramsA->SourceDescription ); - paramsW.SourceTagfile = strdupAtoW( paramsA->SourceTagfile ); - paramsW.TargetDirectory = strdupAtoW( paramsA->TargetDirectory ); - paramsW.TargetFilename = strdupAtoW( paramsA->TargetFilename ); + paramsW.SourceRootPath = MultiByteToUnicode( paramsA->SourceRootPath, CP_ACP ); + paramsW.SourcePath = MultiByteToUnicode( paramsA->SourcePath, CP_ACP ); + paramsW.SourceFilename = MultiByteToUnicode( paramsA->SourceFilename, CP_ACP ); + paramsW.SourceDescription = MultiByteToUnicode( paramsA->SourceDescription, CP_ACP ); + paramsW.SourceTagfile = MultiByteToUnicode( paramsA->SourceTagfile, CP_ACP ); + paramsW.TargetDirectory = MultiByteToUnicode( paramsA->TargetDirectory, CP_ACP ); + paramsW.TargetFilename = MultiByteToUnicode( paramsA->TargetFilename, CP_ACP ); paramsW.CopyStyle = paramsA->CopyStyle; paramsW.LayoutInf = paramsA->LayoutInf; - paramsW.SecurityDescriptor = strdupAtoW( paramsA->SecurityDescriptor ); + paramsW.SecurityDescriptor = MultiByteToUnicode( paramsA->SecurityDescriptor, CP_ACP );
ret = SetupQueueCopyIndirectW( ¶msW );
- heap_free( (WCHAR *)paramsW.SourceRootPath ); - heap_free( (WCHAR *)paramsW.SourcePath ); - heap_free( (WCHAR *)paramsW.SourceFilename ); - heap_free( (WCHAR *)paramsW.SourceDescription ); - heap_free( (WCHAR *)paramsW.SourceTagfile ); - heap_free( (WCHAR *)paramsW.TargetDirectory ); - heap_free( (WCHAR *)paramsW.TargetFilename ); - heap_free( (WCHAR *)paramsW.SecurityDescriptor ); + MyFree( (WCHAR *)paramsW.SourceRootPath ); + MyFree( (WCHAR *)paramsW.SourcePath ); + MyFree( (WCHAR *)paramsW.SourceFilename ); + MyFree( (WCHAR *)paramsW.SourceDescription ); + MyFree( (WCHAR *)paramsW.SourceTagfile ); + MyFree( (WCHAR *)paramsW.TargetDirectory ); + MyFree( (WCHAR *)paramsW.TargetFilename ); + MyFree( (WCHAR *)paramsW.SecurityDescriptor ); return ret; }
@@ -543,10 +543,10 @@ BOOL WINAPI SetupQueueCopyIndirectW( PSP_FILE_COPY_PARAMS_W params )
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE; op->style = params->CopyStyle; - op->src_path = strdupW( params->SourcePath ); - op->src_file = strdupW( params->SourceFilename ); - op->dst_path = strdupW( params->TargetDirectory ); - op->dst_file = strdupW( params->TargetFilename ); + op->src_path = DuplicateString( params->SourcePath ); + op->src_file = DuplicateString( params->SourceFilename ); + op->dst_path = DuplicateString( params->TargetDirectory ); + op->dst_file = DuplicateString( params->TargetFilename );
/* some defaults */ if (!op->dst_file) op->dst_file = op->src_file; @@ -688,8 +688,8 @@ BOOL WINAPI SetupQueueDeleteA( HSPFILEQ handle, PCSTR part1, PCSTR part2 ) struct file_op *op;
if (!(op = heap_alloc_zero( sizeof(*op) ))) return FALSE; - op->dst_path = strdupAtoW( part1 ); - op->dst_file = strdupAtoW( part2 ); + op->dst_path = MultiByteToUnicode( part1, CP_ACP ); + op->dst_file = MultiByteToUnicode( part2, CP_ACP ); queue_file_op( &queue->delete_queue, op ); return TRUE; } @@ -704,8 +704,8 @@ BOOL WINAPI SetupQueueDeleteW( HSPFILEQ handle, PCWSTR part1, PCWSTR part2 ) struct file_op *op;
if (!(op = heap_alloc_zero( sizeof(*op) ))) return FALSE; - op->dst_path = strdupW( part1 ); - op->dst_file = strdupW( part2 ); + op->dst_path = DuplicateString( part1 ); + op->dst_file = DuplicateString( part2 ); queue_file_op( &queue->delete_queue, op ); return TRUE; } @@ -721,10 +721,10 @@ BOOL WINAPI SetupQueueRenameA( HSPFILEQ handle, PCSTR SourcePath, PCSTR SourceFi struct file_op *op;
if (!(op = heap_alloc_zero( sizeof(*op) ))) return FALSE; - op->src_path = strdupAtoW( SourcePath ); - op->src_file = strdupAtoW( SourceFilename ); - op->dst_path = strdupAtoW( TargetPath ? TargetPath : SourcePath ); - op->dst_file = strdupAtoW( TargetFilename ); + op->src_path = MultiByteToUnicode( SourcePath, CP_ACP ); + op->src_file = MultiByteToUnicode( SourceFilename, CP_ACP ); + op->dst_path = MultiByteToUnicode( TargetPath ? TargetPath : SourcePath, CP_ACP ); + op->dst_file = MultiByteToUnicode( TargetFilename, CP_ACP ); queue_file_op( &queue->rename_queue, op ); return TRUE; } @@ -740,10 +740,10 @@ BOOL WINAPI SetupQueueRenameW( HSPFILEQ handle, PCWSTR SourcePath, PCWSTR Source struct file_op *op;
if (!(op = heap_alloc_zero( sizeof(*op) ))) return FALSE; - op->src_path = strdupW( SourcePath ); - op->src_file = strdupW( SourceFilename ); - op->dst_path = strdupW( TargetPath ? TargetPath : SourcePath ); - op->dst_file = strdupW( TargetFilename ); + op->src_path = DuplicateString( SourcePath ); + op->src_file = DuplicateString( SourceFilename ); + op->dst_path = DuplicateString( TargetPath ? TargetPath : SourcePath ); + op->dst_file = DuplicateString( TargetFilename ); queue_file_op( &queue->rename_queue, op ); return TRUE; } @@ -1477,7 +1477,7 @@ BOOL WINAPI SetupCommitFileQueueW( HWND owner, HSPFILEQ handle, PSP_FILE_CALLBAC lstrcatW(op->media->root, L"\"); lstrcatW(op->media->root, op->src_path);
- heap_free(op->src_path); + MyFree(op->src_path); op->src_path = NULL; }
diff --git a/dlls/setupapi/setupapi_private.h b/dlls/setupapi/setupapi_private.h index 77d34176c45..c4d68e9e1fe 100644 --- a/dlls/setupapi/setupapi_private.h +++ b/dlls/setupapi/setupapi_private.h @@ -63,35 +63,12 @@ static inline WCHAR *strdupW( const WCHAR *str ) return ret; }
-static inline char *strdupWtoA( const WCHAR *str ) -{ - char *ret = NULL; - if (str) - { - DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL ); - if ((ret = HeapAlloc( GetProcessHeap(), 0, len ))) - WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL ); - } - return ret; -} - -static inline WCHAR *strdupAtoW( const char *str ) -{ - WCHAR *ret = NULL; - if (str) - { - DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); - if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) - MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len ); - } - return ret; -} - /* exported functions not in public headers */
void WINAPI MyFree( void *mem ); void * WINAPI MyMalloc( DWORD size ) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(MyFree) __WINE_MALLOC; void * WINAPI MyRealloc( void *src, DWORD size ) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(MyFree); +WCHAR * WINAPI DuplicateString( const WCHAR *str ) __WINE_DEALLOC(MyFree) __WINE_MALLOC; WCHAR * WINAPI MultiByteToUnicode( const char *str, UINT code_page ) __WINE_DEALLOC(MyFree) __WINE_MALLOC; char * WINAPI UnicodeToMultiByte( const WCHAR *str, UINT code_page ) __WINE_DEALLOC(MyFree) __WINE_MALLOC;
I've disabled the tests for MultiByteToUnicode(NULL, CP_ACP) and UnicodeToMultiByte(NULL, CP_ACP) because they crash on Windows 10, although they pass on every previous version of Windows that I could test.