From 8dd8a9d989c1d438e4bb0f912c197a601e6d745e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 8 Oct 2016 14:48:18 +0000 Subject: [PATCH] [PING] - Use a dynamic-allocated buffer with FormatMessageW, fixes messages disappearance (eg. ping help in russian). CORE-12108 #comment Fixed in r72943. - Remove the unneeded 1-line function "Usage" and instead just directly call the corresponding PrintString function. svn path=/trunk/; revision=72943 --- reactos/base/applications/network/ping/ping.c | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/reactos/base/applications/network/ping/ping.c b/reactos/base/applications/network/ping/ping.c index a82ce2a6201..6c31607c9f3 100644 --- a/reactos/base/applications/network/ping/ping.c +++ b/reactos/base/applications/network/ping/ping.c @@ -49,7 +49,6 @@ static BOOL ParseCmdLine(int argc, PWSTR argv[]); static BOOL ResolveTarget(PCWSTR target); -static void Usage(void); static void Ping(void); static void PrintStats(void); static BOOL WINAPI ConsoleCtrlHandler(DWORD ControlType); @@ -180,46 +179,37 @@ static void PrintString(UINT id, ...) { - WCHAR Format[1024]; - WCHAR Msg[1024]; - DWORD Len, written; +#define RC_STRING_MAX_SIZE 4096 + + WCHAR Format[RC_STRING_MAX_SIZE]; + LPWSTR lpMsgBuf = NULL; + DWORD Len; va_list args; if (!LoadStringW(GetModuleHandleW(NULL), id, Format, _countof(Format))) { DPRINT("LoadStringW failed: %lu\n", GetLastError()); - return; } va_start(args, id); - Len = FormatMessageW( - FORMAT_MESSAGE_FROM_STRING, - Format, 0, 0, - Msg, 1024, &args); - - if (Len == 0) + Len = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, + Format, 0, 0, (PWSTR)&lpMsgBuf, 0, &args); + if (lpMsgBuf /* && Len != 0 */) + { + // TODO: Handle writing to file. Well, use the ConUtils lib! + WriteConsoleW(hStdOut, lpMsgBuf, Len, &Len, NULL); + LocalFree(lpMsgBuf); + } + else { DPRINT("FormatMessageW failed: %lu\n", GetLastError()); - - va_end(args); - return; } - // TODO: Handle writing to file. - WriteConsole(hStdOut, Msg, Len, &written, NULL); - va_end(args); } -static -void -Usage(void) -{ - PrintString(IDS_USAGE); -} - static BOOL ParseCmdLine(int argc, PWSTR argv[]) @@ -228,8 +218,7 @@ ParseCmdLine(int argc, PWSTR argv[]) if (argc < 2) { - Usage(); - + PrintString(IDS_USAGE); return FALSE; } @@ -404,14 +393,12 @@ ParseCmdLine(int argc, PWSTR argv[]) break; case L'?': - Usage(); - + PrintString(IDS_USAGE); return FALSE; default: PrintString(IDS_BAD_OPTION, argv[i]); - Usage(); - + PrintString(IDS_USAGE); return FALSE; } }