ancruna / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

remove memsets to zero #316

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. view the code

What is the expected output? What do you see instead?
all is ok

What version of the product are you using? On what operating system?
HEAD

Please provide any additional information below.

You can see in the constructs such as:
  STARTUPINFOA si;
  PROCESS_INFORMATION pi;

  envp = NULL; // Unused

  (void) memset(&si, 0, sizeof(si));
  (void) memset(&pi, 0, sizeof(pi));

  // TODO(lsm): redirect CGI errors to the error log file
  si.cb  = sizeof(si);
  si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  si.wShowWindow = SW_HIDE;

but you could have easily written:

  STARTUPINFOA si = { sizeof(si) };
  PROCESS_INFORMATION pi = {};

  envp = NULL; // Unused

  // TODO(lsm): redirect CGI errors to the error log file
  si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  si.wShowWindow = SW_HIDE;

And save some eye fatigue to the code reader.

Original issue reported on code.google.com by janez...@gmail.com on 16 Feb 2012 at 7:29

GoogleCodeExporter commented 9 years ago
 STARTUPINFOA si = { sizeof(si) };
This relies on field order, which is probably fine in this case. 

PROCESS_INFORMATION pi = {};
That's not valid ISO C, you can't pass an empy initializer list afaik.

Original comment by valenok on 4 Mar 2012 at 5:13

GoogleCodeExporter commented 9 years ago
Of course it is, if field order were to change, other code would stop
working also

Of course it is valid, why don't you try? I use this construct many times.

All in all, you did not specify why you won't fix.

Original comment by janez...@gmail.com on 4 Mar 2012 at 5:25

GoogleCodeExporter commented 9 years ago
GCC gives me a warning about missing initializers.
However, I've poked around a bit, and apparently you're right,
this is a valid C99 construct. And it looks like it is a useful idiom.

Thank you, I'll start to use it from now on.
Submitted 
http://code.google.com/p/mongoose/source/detail?r=0d6e197ba81444fc39d3a7054be455
b49838fd1e

Original comment by valenok on 4 Mar 2012 at 7:41