title: Valgrind gives an error for nearly everything (Warning: client switching stacks?)
body: <p>I'm corrupting memory somehow because my program crashes without error at random places.</p>
  
  <p>I'm using valgrind with <code>--leak-check=full</code>, compiling with <code>-O0 -g</code>, and the very first problem it detects is the first line in <code>int main()</code></p>
  
  <pre><code>cout &lt;&lt; "reading file" &lt;&lt; endl;
  </code></pre>
  
  <p>with </p>
  
  <pre><code>==5089== Warning: client switching stacks?  SP change: 0x7ff0004f8 --&gt; 0x7feb7de10
  ==5089==          to suppress, use: --max-stackframe=4728552 or greater
  ==5089== Invalid write of size 8
  ==5089==    at 0x41E107: main (Dgn.cpp:2833)
  ==5089==  Address 0x7feb7de08 is on thread 1's stack
  </code></pre>
  
  <p>It goes on with</p>
  
  <pre><code>==5089== Invalid read of size 8
  ==5089==    at 0x5DE6E10: std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
  ==5089==    by 0x67AEDE4: (below main) (libc-start.c:260)
  ==5089==  Address 0x7feb7de08 is on thread 1's stack
  ==5089== 
  ==5089== Invalid write of size 8
  ==5089==    at 0x5DBF8F2: std::ios_base::ios_base() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
  ==5089==    by 0x5E06BFF: std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ifstream(char const*, std::_Ios_Openmode) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
  ==5089==    by 0x41E131: main (Dgn.cpp:2834)
  ==5089==  Address 0x7feb7e1e8 is on thread 1's stack
  </code></pre>
  
  <p>which points to </p>
  
  <pre><code>ifstream config_file("file");
  </code></pre>
  
  <p>Nearly every line has an error.</p>
  
  <p>What causes this?</p>