title: Uninitialized structure members: best practice
body: <p>In my code I have a struct like this:</p>
  
  <pre><code>struct fileinfo {
      /* ... */
      bool hashed;
      char hash[20];
  }
  </code></pre>
  
  <p>Each function that processes a <code>struct fileinfo</code> does only read the value of <code>hash</code> if and only if <code>hashed</code> is set. My program writes a couple of these <code>struct fileinfo</code>'s into a temporary file to be used later on:</p>
  
  <pre><code>struct fileinfo info;
  
  /* ... */
  
  info.hashed = false;
  
  /* ... */
  
  if (fwrite(&amp;info,sizeof info,1,m-&gt;info_file) != 1) {
       perror("Error writing to temporary file");
       return 1;
  }
  </code></pre>
  
  <p>Valgrind now complains that I pass uninitialized memory to the system call <code>write</code>. What is the best practice to deal with such a case? Is it the best idea to simply <code>memset</code> the member <code>hash</code> to zero bytes beforehand?</p>