title: Trapping uninitialized pointers
body: <p>I am trying to trap bad pointers being passed to functions. On a bare metal embedded application I used to use:</p>
  
  <pre><code>assert(somePointer != NULL);
  </code></pre>
  
  <p>This worked marginally well, if the particular memory location of the pointer was zero initialised. </p>
  
  <p>I notice that FreeRTOS, and others such as RTX, fill the memory with a pattern such as 0xA5 (to do stack usage high level watermarking). Thus, an unitialised pointer will have some non zero initial value.</p>
  
  <p>Ofcourse, I realise that even a zero initialised memory will become non-zero. As such, I am hoping someone has a better approach for detecting uninitialised pointers.</p>
  
  <p>Since this is an embedded system, I was thinking of having a function check that the pointer is in the correct memory range. On the ST32F4xx that would be 0x20000000 to 0x20020000, or 0x10000000 to 0x10010000 and the peripheral address range as well.</p>
  
  <p>The biggest cause of the unitialised pointers is generally a peripheral handle struct that was declared uninitialised in firmware libraries. The assert() macro used to help detect these as soon as possible.</p>
  
  <p>Suggestions are welcome    </p>