title: "Uninitialised value was created by a stack allocation" in c++ std::map
body: <p>Valgrind tells me that there is an error in my code, but I am not able to find it...
  here is a code snippet:</p>
  
  <pre><code>22 int main(int argc, char *argv[]){
  ...
  //argv[1] contains the name of a file
  int length=atoi(argv[2]);
  map&lt;string, double&gt; Map;
  char* Key;
  Key = new char [length+1];
  ...
  </code></pre>
  
  <p>I also used <code>Key[length]='\0'</code> but this does't seem to affect the rest of the code.</p>
  
  <p>now I fill in the map with entries taken from a file (which contains a list of keys and values rows. The dimension of Key is always lower of length.</p>
  
  <pre><code>while( file_stream &gt;&gt; Key &gt;&gt; Value){
  Map[Key]=Value;
  ....
  }
  </code></pre>
  
  <p>at this point, I call:</p>
  
  <pre><code>cout &lt;&lt; Key  &lt;&lt; " has value ";
  159   cout &lt;&lt; Map[Key] &lt;&lt; endl;
  </code></pre>
  
  <p>The program is compiled and executed nicely, but Valgrind give lots of errors of this type:</p>
  
  <pre><code>==6921== Conditional jump or move depends on uninitialised value(s)
  ==6921==    at 0x56274A0: __printf_fp (printf_fp.c:404)
  ==6921==    by 0x562396A: vfprintf (vfprintf.c:1622)
  ==6921==    by 0x5648C81: vsnprintf (vsnprintf.c:120)
  ==6921==    by 0x4EB64AE: ??? (in /usr/lib/libstdc++.so.6.0.13)
  ==6921==    by 0x4EB9002: std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; std::num_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::_M_insert_float&lt;double&gt;(std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, char, char, double) const (in /usr/lib/libstdc++.so.6.0.13)
  ==6921==    by 0x4EB9328: std::num_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::do_put(std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, char, double) const (in /usr/lib/libstdc++.so.6.0.13)
  ==6921==    by 0x4ECCC9E: std::ostream&amp; std::ostream::_M_insert&lt;double&gt;(double) (in /usr/lib/libstdc++.so.6.0.13)
  ==6921==    by 0x40366E: main (MyProgram.cpp:159)
  ==6921==  Uninitialised value was created by a stack allocation
  ==6921==    at 0x401C61: main (MyProgram.cpp:22)
  </code></pre>
  
  <p>Do you have any idea any clue? I would prefer to not post all the long code (please don't blame for this)</p>
  
  <p>Thanks!!</p>