diff --git a/dlls/kernel32/format_msg.c b/dlls/kernel32/format_msg.c index 8c374346d97..db97300f88d 100644 --- a/dlls/kernel32/format_msg.c +++ b/dlls/kernel32/format_msg.c @@ -752,8 +752,7 @@ DWORD WINAPI FormatMessageW( TRACE("-- %s\n",debugstr_w(target)); if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { /* nSize is the MINIMUM size */ - DWORD len = strlenW(target) + 1; - *((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT,len*sizeof(WCHAR)); + *((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT, max(nSize, talloced)*sizeof(WCHAR)); strcpyW(*(LPWSTR*)lpBuffer, target); } else