title: PREfast annotation for structure members
body: <p>In my company's code we have general get() and set() methods for interop between certain components. However, if I try to run PREfast I get inundated with warnings because PREfast doesn't realize that the get() method initializes the given parameters.</p>
  
  <p>The problem is that since those methods are very general, they don't simply take a parameter (which I could mark with <code>_Out_</code> or similar, but an array of structs which holds the data as to which data should be returned.</p>
  
  <p>In code (greatly simplified):</p>
  
  <pre><code>typedef struct
  {
      int type;
      int* data;
  } ARGS;
  
  void get(int count, ARGS* args)
  {
      for (int i = 0; i &lt; count; i++)
          *(args[i].data) = 42; // Actually handled by internal methods
  }
  
  // Sample Usage
  void foo()
  {
      int value;
      ARGS args[1];
  
      args[0].type = 1234;
      args[0].data = &amp;value;
  
      get(1, args);
  
      // Do something with value
      // PREfast complains that value is uninitialized (error C6001)
      printf("%d", value);
  }
  </code></pre>
  
  <p>Is there any way to annotate this so PREfast knows that <code>args.data</code> is initialized by <code>get()</code>? Or is this too complex for PREfast to handle?</p>
  
  <p>EDIT: If I use <code>get(1, &amp;args)</code>, then the warning goes away. So there is some heuristic in PREfast which can handle this case, but I haven't found out if it is possible to trigger it externally:</p>
  
  <pre><code>void get2(int count, ARGS(* args)[1]) // Needs the size of args, or it won't compile below
  {
      for (int i = 0; i &lt; count; i++)
          *(*args)[i].data = 42; // Actually handled by internal methods
  }
  
  // Sample Usage
  void foo2()
  {
      int value;
      ARGS args[1];
  
      args[0].type = 1234;
      args[0].data = &amp;value;
  
      get2(1, &amp;args);
  
      // Do something with value
      printf("%d", value);
  }
  </code></pre>