From 31acbb4b9c9f7ac679b73e4261b0515cb0a9d584 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Wed, 13 Dec 2000 01:50:19 +0000 Subject: [PATCH] FormatMessageA wasn't properly handling the %ls modifier. --- dlls/kernel/format_msg.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dlls/kernel/format_msg.c b/dlls/kernel/format_msg.c index c943d76510e..23b156e58b2 100644 --- a/dlls/kernel/format_msg.c +++ b/dlls/kernel/format_msg.c @@ -244,13 +244,10 @@ DWORD WINAPI FormatMessageA( if (NULL!=(x=strchr(f,'!'))) { *x='\0'; fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2); - /* %ls ? */ - if (!strcmp(f,"ls")) f++; sprintf(fmtstr,"%%%s",f); f=x+1; } else { fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2); - if (!strcmp(f,"ls")) f++; sprintf(fmtstr,"%%%s",f); f+=strlen(f); /*at \0*/ } @@ -261,17 +258,25 @@ DWORD WINAPI FormatMessageA( fmtstr=HEAP_strdupA(GetProcessHeap(),0,"%s"); if (args) { int sz; - LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100); + LPSTR b; if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) argliststart=args+insertnr-1; else argliststart=(*(DWORD**)args)+insertnr-1; - /* CMF - This makes a BIG assumption about va_list */ - while (vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) { - b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz += 100); - } + /* FIXME: precision and width components are not handled correctly */ + if (strcmp(fmtstr, "%ls") == 0) { + sz = WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, NULL, 0, NULL, NULL); + b = HeapAlloc(GetProcessHeap(), 0, sz); + WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, b, sz, NULL, NULL); + } else { + b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100); + /* CMF - This makes a BIG assumption about va_list */ + while (vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) { + b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz += 100); + } + } for (x=b; *x; x++) ADD_TO_T(*x); HeapFree(GetProcessHeap(),0,b); -- 2.11.4.GIT