CreateProcess variable definition
When calling CreateProcess you can use the StartupInfo and ProcessInformation structures to specify/retrieve some extra information about the process being created. In a lot of examples you'll see something like this:
Code:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
CreateProcess(...);
Which is kind of surprising to me since I don't see any remarks about this on the corresponding MSDN page.
I understand that if you're creating a process that makes use of the StartupInfo struct it is important to make sure that StartupInfo struct being passed doesn't contain any garbage data. So even if you don't need to specify any StartupInfo options this struct should be zero'd if the process being created depends on it.
But this doesn't seem to be the case with the ProcessInformation struct. The system will fill all the members of this struct with the appropriate information and it's up to the caller to decide what to do with it.
Question 1: If you're absolutely certain that the process being created will not do anything with the StartupInfo struct, is it safe to pass it to CreateProcess while containing garbage data?
Question 2: Why zero the ProcessInformation struct before calling CreateProcess when the system will always fill this struct with the appropriate information? Shouldn't it be perfectly fine to pass this struct while it contains garbage data in any case?
Question 3: In the situation described above is it correct to define/declare these structs as such before calling CreateProcess?
Code:
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
CreateProcess(...);