]> git.saurik.com Git - wxWidgets.git/commitdiff
don't crash if FormatMessage() fails in wxSysErrorMsg()
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Jun 2005 22:05:16 +0000 (22:05 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Jun 2005 22:05:16 +0000 (22:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/log.cpp

index 37143c97c4c000ac7b3b18f75b4c9639f20a3b30..476f39db249f9d629a0b59ca0ccc4d7f7648f539 100644 (file)
@@ -737,14 +737,26 @@ const wxChar *wxSysErrorMsg(unsigned long nErrCode)
 
     // get error message from system
     LPVOID lpMsgBuf;
-    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-            NULL, nErrCode,
+    if ( ::FormatMessage
+         (
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+            NULL,
+            nErrCode,
             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
             (LPTSTR)&lpMsgBuf,
-            0, NULL);
+            0,
+            NULL
+         ) == 0 )
+    {
+        // if this happens, something is seriously wrong, so don't use _() here
+        // for safety
+        wxSprintf(s_szBuf, _T("unknown error %lx"), nErrCode);
+               return s_szBuf;
+    }
+
 
     // copy it to our buffer and free memory
-    // Crashes on SmartPhone
+    // Crashes on SmartPhone (FIXME)
 #if !defined(__SMARTPHONE__) /* of WinCE */
      if( lpMsgBuf != 0 ) {
         wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1);