title: Invalid pointer becoming valid again
body: <pre><code>int *p;
  {
      int x = 0;
      p = &amp;x;
  }
  // p is no longer valid
  {
      int x = 0;
      if (&amp;x == p) {
          *p = 2;  // Is this valid?
      }
  }
  </code></pre>
  
  <p>Accessing a pointer after the thing it points to has been freed is undefined behavior, but what happens if some later allocation happens in the same area, and you explicitly compare the old pointer to a pointer to the new thing? Would it have mattered if I cast <code>&amp;x</code> and <code>p</code> to <code>uintptr_t</code> before comparing them?</p>
  
  <p>(I know it's not guaranteed that the two <code>x</code> variables occupy the same spot. I have no reason to do this, but I can imagine, say, an algorithm where you intersect a set of pointers that might have been freed with a set of definitely valid pointers, removing the invalid pointers in the process. If a previously-invalidated pointer is equal to a known good pointer, I'm curious what would happen.)</p>