VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Setup/Setup.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-25 23:34:30 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-26 00:44:54 (GMT)
commit59611b8b378238e5a589a87061d06fe4f337d1a0 (patch)
tree5d16a47f96e70cd7c581880193b48f73c38485bc /src/Setup/Setup.c
parent90bd57fe40e66fc829ecb01482d32d604b0df19c (diff)
downloadVeraCrypt-59611b8b378238e5a589a87061d06fe4f337d1a0.zip
VeraCrypt-59611b8b378238e5a589a87061d06fe4f337d1a0.tar.gz
Windows: solve crash caused by system function FormatMessage failure on rare cases.
Diffstat (limited to 'src/Setup/Setup.c')
-rw-r--r--src/Setup/Setup.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c
index fd6d891..828de70 100644
--- a/src/Setup/Setup.c
+++ b/src/Setup/Setup.c
@@ -941,9 +941,11 @@ err:
LPVOID lpMsgBuf;
DWORD dwError = GetLastError ();
wchar_t szTmp2[700];
+ wchar_t szErrorValue[16];
+ wchar_t* pszDesc;
FormatMessage (
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
@@ -952,13 +954,20 @@ err:
NULL
);
+ if (lpMsgBuf)
+ pszDesc = (wchar_t*) lpMsgBuf;
+ else
+ {
+ StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"0x%.8X", dwError);
+ pszDesc = szErrorValue;
+ }
if (bUninstall == FALSE)
- StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("INSTALL_OF_FAILED"), szTmp, lpMsgBuf);
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("INSTALL_OF_FAILED"), szTmp, pszDesc);
else
- StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("UNINSTALL_OF_FAILED"), szTmp, lpMsgBuf);
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("UNINSTALL_OF_FAILED"), szTmp, pszDesc);
- LocalFree (lpMsgBuf);
+ if (lpMsgBuf) LocalFree (lpMsgBuf);
if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
return FALSE;