[cmake-commits] king committed cmWin32ProcessExecution.cxx 1.28 1.29

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Oct 5 13:43:07 EDT 2006


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv1203

Modified Files:
	cmWin32ProcessExecution.cxx 
Log Message:
BUG: Robustly handle failure of FormatMessage.  See bug#3471.


Index: cmWin32ProcessExecution.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmWin32ProcessExecution.cxx,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- cmWin32ProcessExecution.cxx	1 Aug 2006 15:38:42 -0000	1.28
+++ cmWin32ProcessExecution.cxx	5 Oct 2006 17:43:02 -0000	1.29
@@ -442,26 +442,26 @@
     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 @@
     output += path;
     }
   output += "\n";
-  delete [] str;
   free(s2);
   free(s1);
   return FALSE;



More information about the Cmake-commits mailing list