summaryrefslogtreecommitdiffstats
path: root/Source/cmWin32ProcessExecution.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-10-05 17:43:02 (GMT)
committerBrad King <brad.king@kitware.com>2006-10-05 17:43:02 (GMT)
commit5341711012b8d3787d154a5c2e04ead5aa920edd (patch)
treee5d352b9df88dea1f4aa938f469310412aa0f68e /Source/cmWin32ProcessExecution.cxx
parent97e07dc162a57c22d9dd0f4b89f192c2084f7ce7 (diff)
downloadCMake-5341711012b8d3787d154a5c2e04ead5aa920edd.zip
CMake-5341711012b8d3787d154a5c2e04ead5aa920edd.tar.gz
CMake-5341711012b8d3787d154a5c2e04ead5aa920edd.tar.bz2
BUG: Robustly handle failure of FormatMessage. See bug#3471.
Diffstat (limited to 'Source/cmWin32ProcessExecution.cxx')
-rw-r--r--Source/cmWin32ProcessExecution.cxx37
1 files changed, 18 insertions, 19 deletions
diff --git a/Source/cmWin32ProcessExecution.cxx b/Source/cmWin32ProcessExecution.cxx
index ed7b1ea..6e62990 100644
--- a/Source/cmWin32ProcessExecution.cxx
+++ b/Source/cmWin32ProcessExecution.cxx
@@ -442,26 +442,26 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
free(s1);
return TRUE;
}
-
- LPVOID lpMsgBuf;
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
-
- // Free the buffer.
-
- char* str = strcpy(new char[strlen((char*)lpMsgBuf)+1], (char*)lpMsgBuf);
- LocalFree( lpMsgBuf );
-
output += "CreateProcessError: ";
- output += str;
+ {
+ /* Format the error message. */
+ char message[1024];
+ DWORD original = GetLastError();
+ DWORD length = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS, 0, original,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ message, 1023, 0);
+ if(length < 1)
+ {
+ /* FormatMessage failed. Use a default message. */
+ _snprintf(message, 1023,
+ "Process execution failed with error 0x%X. "
+ "FormatMessage failed with error 0x%X",
+ original, GetLastError());
+ }
+ output += message;
+ }
output += "\n";
output += "for command: ";
output += s2;
@@ -471,7 +471,6 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
output += path;
}
output += "\n";
- delete [] str;
free(s2);
free(s1);
return FALSE;