how to detect or avoid using C++ uninitialized pointer?
<p>I got an uninitialized pointer problem today. unfortunately, it caused core dump after it released.</p>

<p>here is the sample code, and the function print_request() is new code, and this function could be used by several other functions:</p>

<pre><code>// def.h
struct INFO {
  uint32_t val1;
  uint32_t val2;  
};

struct INFO_LIST {
  uint32_t id;
  struct INFO * data;
};

// util.cpp
void print_request(const struct INFO_LIST req)
{
  fprintf(stdout, "%u\t%u\t%u\n", req.id, req.data-&gt;val1, req.data-&gt;val2);
}

// A.cpp
int parse_ie(...)
{
  // ...
  struct INFO_LIST req;
  req.id = 10;
  req.data = new INFO();
  req.val1 = 101;
  req.val2 = 102;

  print_request(req);

  // ...
}
// B.cpp
int parse_chrome(...)
{
  // ...
  struct INFO_LIST req;
  req.id = 20;

  print_request(req);  // core dump here!

  // ...
}
</code></pre>

<p>here is what I have done:</p>

<ol>
<li><p>I have wroten the unit test for print_request(), but I forgot there is an uninitialized pointer while function parse_chrome() use it.</p></li>
<li><p>I analyzer the code by using the static code analyzer tool, for example, cppcheck, and there is no error or warning.</p></li>
<li><p>it is still ignored after code reviewing.</p></li>
</ol>

<p>so, I want to know:</p>

<ol>
<li><p>is there any good tool to detect the uninitialized pointer in C++?</p></li>
<li><p>how to avoid using uninitialized pointer in C++?</p></li>
</ol>

<p>any suggestion would be appreciated, thank you!</p>

<p>PS, I want to write uniform functions to call the pointer, but it would cost much time.</p>

<p>PPS. sorry, variable "req" is not a pointer. my fault.</p>