Author: hbelusca
Date: Mon Oct 3 12:22:29 2016
New Revision: 72897
URL:
http://svn.reactos.org/svn/reactos?rev=72897&view=rev
Log:
[CLIPBRD][EVENTVWR][MPLAY32][WELCOME][SYSDM]
Fix the ShowLastWin32Error helpers:
- don't display the last error string if it's ERROR_SUCCESS (since the code
usually expects to display the last error message in case of errors);
- *always* call FormatMessage with the FORMAT_MESSAGE_IGNORE_INSERTS flag enabled. Indeed
if it happens that the message string associated to an error ID contains insert parameter
placeholders, and since we don't give here FormatMessage any argument array, the call
would result into a crash without this flag.
Modified:
trunk/reactos/base/applications/clipbrd/winutils.c
trunk/reactos/base/applications/mplay32/mplay32.c
trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.c
trunk/reactos/base/setup/welcome/welcome.c
trunk/reactos/dll/cpl/sysdm/general.c
Modified: trunk/reactos/base/applications/clipbrd/winutils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/clipbrd/…
==============================================================================
--- trunk/reactos/base/applications/clipbrd/winutils.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/clipbrd/winutils.c [iso-8859-1] Mon Oct 3 12:22:29
2016
@@ -14,9 +14,21 @@
LPWSTR lpMsgBuf = NULL;
dwError = GetLastError();
-
- FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
+ if (dwError == ERROR_SUCCESS)
+ return;
+
+ if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&lpMsgBuf,
+ 0, NULL))
+ {
+ return;
+ }
+
MessageBoxW(hwndParent, lpMsgBuf, NULL, MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
Modified: trunk/reactos/base/applications/mplay32/mplay32.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mplay32/…
==============================================================================
--- trunk/reactos/base/applications/mplay32/mplay32.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mplay32/mplay32.c [iso-8859-1] Mon Oct 3 12:22:29
2016
@@ -209,16 +209,23 @@
LPTSTR lpMessageBuffer;
DWORD dwError = GetLastError();
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMessageBuffer,
- 0, NULL) != 0)
- {
- MessageBox(hwnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR);
- if (lpMessageBuffer) LocalFree(lpMessageBuffer);
- }
+ if (dwError == ERROR_SUCCESS)
+ return;
+
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPTSTR)&lpMessageBuffer,
+ 0, NULL))
+ {
+ return;
+ }
+
+ MessageBox(hwnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR);
+ LocalFree(lpMessageBuffer);
}
static VOID
Modified: trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.c [iso-8859-1] Mon Oct 3
12:22:29 2016
@@ -245,13 +245,20 @@
LPWSTR lpMessageBuffer;
dwError = GetLastError();
- FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- 0,
- (LPWSTR)&lpMessageBuffer,
- 0,
- NULL);
+ if (dwError == ERROR_SUCCESS)
+ return;
+
+ if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&lpMessageBuffer,
+ 0, NULL))
+ {
+ return;
+ }
MessageBoxW(hwndMainWindow, lpMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
LocalFree(lpMessageBuffer);
Modified: trunk/reactos/base/setup/welcome/welcome.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/welcome/welcome…
==============================================================================
--- trunk/reactos/base/setup/welcome/welcome.c [iso-8859-1] (original)
+++ trunk/reactos/base/setup/welcome/welcome.c [iso-8859-1] Mon Oct 3 12:22:29 2016
@@ -113,20 +113,23 @@
LPTSTR lpMessageBuffer = NULL;
DWORD dwError = GetLastError();
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMessageBuffer,
- 0, NULL))
- {
- MessageBox(hWnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR);
- }
-
- if (lpMessageBuffer)
- {
- LocalFree(lpMessageBuffer);
- }
+ if (dwError == ERROR_SUCCESS)
+ return;
+
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPTSTR)&lpMessageBuffer,
+ 0, NULL))
+ {
+ return;
+ }
+
+ MessageBox(hWnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR);
+ LocalFree(lpMessageBuffer);
}
#endif
Modified: trunk/reactos/dll/cpl/sysdm/general.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/sysdm/general.c?re…
==============================================================================
--- trunk/reactos/dll/cpl/sysdm/general.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/sysdm/general.c [iso-8859-1] Mon Oct 3 12:22:29 2016
@@ -35,23 +35,23 @@
DWORD LastError;
LastError = GetLastError();
-
- if ((LastError == 0) ||
- !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- LastError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsg,
- 0,
- NULL))
- {
+ if (LastError == ERROR_SUCCESS)
return;
+
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ LastError,
+ LANG_USER_DEFAULT,
+ (LPTSTR)&lpMsg,
+ 0, NULL))
+ {
+ return;
}
MessageBox(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR);
-
- LocalFree((LPVOID)lpMsg);
+ LocalFree(lpMsg);
}