Debugging seg fault caused by buffer over run
<p>I have the following code:</p>

<pre><code>if (destIndex &lt; destLen &amp;&amp; srcIndex &lt; srcLen)
    dest[destIndex++] = src[srcIndex++];
</code></pre>

<p>This code runs fine.</p>

<p>If I remove the  if, then the code crashes.</p>

<p>If I then run the following code</p>

<pre><code>if (destIndex &lt; destLen &amp;&amp; srcIndex &lt; srcLen)
    dest[destIndex++] = src[srcIndex++];
else
   fprintf(stderr, "Buffer Overrun\n");
</code></pre>

<p>Then I never get the print out "Buffer Overrun"</p>

<p>SO, how to debug this? </p>

<p>The seg fault only happens with optimizations turned on (no debug mode)</p>