title: Getting warning - Dereferencing before possibly being null in C code
body: <p>I'm getting a warning while doing a Static Analysis (SA) on my code. I have simplified it below (with the first warning)-</p>
  
  <pre><code>typedef struct testStruct_ {
  int *ptr;
  } testStruct;
  
  testStruct a;
  testStruct *a_ptr;
  a_ptr = &amp;a;
  a_ptr-&gt;ptr = NULL; #WARNING: Directly dereferencing pointer a_ptr.
  </code></pre>
  
  <p>The code goes on to do several operations with <code>a_ptr</code>. 
  I've posted an example for the sake of completion-</p>
  
  <pre><code>rc = fn_a (filename, a_ptr);
  rc = fn_b (a_ptr);
  rc = fn_c (a_ptr-&gt;ptr);
  </code></pre>
  
  <p>fn_a is defined as-</p>
  
  <pre><code>fn_a (const char *filename, testStruct *a_ptr)
  {
      a_ptr-&gt;ptr = fn_a_2(filename);
      if (!a_ptr-&gt;ptr) {
          ERR("Loading (%s) failed", filename);
          return (FALSE);
      }
      return (TRUE);
  }
  </code></pre>
  
  <p>At one point later, I get another warning:</p>
  
  <pre><code>if (a_ptr &amp;&amp; a_ptr-&gt;ptr) {
      freeFn(a_ptr-&gt;ptr);
  }
  #WARNING: Dereference before NULL check - NULL checking a_ptr suggests that it may be NULL, but it has already been dereferenced on all paths leading up to the check.
  </code></pre>
  
  <p>It seems like the line <code>a_ptr-&gt;ptr = NULL</code> is deemed incorrect/dangerous. Why is this error being shown and is there a way to correct it?</p>