fixed handling of variable arguments and free memory allocated by FormatMessage(...
authorThomas Bluemel <thomas@reactsoft.com>
Wed, 23 Jun 2004 19:32:17 +0000 (19:32 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Wed, 23 Jun 2004 19:32:17 +0000 (19:32 +0000)
svn path=/trunk/; revision=9833

reactos/subsys/system/cmd/console.c

index 33e9250..e5e2264 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: console.c,v 1.6 2004/06/21 18:57:22 weiden Exp $
+/* $Id: console.c,v 1.7 2004/06/23 19:32:17 weiden Exp $
  *
  *  CONSOLE.C - console input/output functions.
  *
@@ -225,17 +225,29 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
 
 VOID ConOutFormatMessage (DWORD MessageId, ...)
 {
-       DWORD temp;
+       DWORD ret;
        LPTSTR text;
        va_list arg_ptr;
-       temp = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+       
+       va_start (arg_ptr, MessageId);
+       ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
               NULL,
               MessageId,
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR) &text,
               0,
               &arg_ptr);
-       ConErrPrintf (text);    
+       
+       va_end (arg_ptr);
+       if(ret > 0)
+       {
+               ConErrPuts (text);
+               LocalFree(text);
+       }
+       else
+       {
+               ConErrPrintf (_T("Unknown error: %d\n"), MessageId);
+       }
 }
 
 VOID ConOutPrintf (LPTSTR szFormat, ...)