title: Visual C++: Invalid allocation size. How to force the debugger to stop on this message?
body: <p>The MFC program I am debugging is printing this message in the "Output" window in Visual Studio 9.0:</p>
  
  <pre><code>HEAP[AppName.exe]: Invalid allocation size - 99999998 (exceeded 7ffdefff)
  </code></pre>
  
  <p>I'm pretty sure this is due to a bad "new", uninitialized variable or similar error.</p>
  
  <p>The question is: how do I get the debugger to stop on this message so that I can view the stack trace and solve the problem?</p>
  
  <hr>
  
  <p>Edit: The following snippets do not yield the same warning. They produce the <code>Invalid allocation size: 4294967295 bytes.</code> style message instead.</p>
  
  <pre><code>int stupid = -1;
  char *bob = new char[stupid];
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>malloc(-1);
  </code></pre>
  
  <p>So, I suspect it's coming from within a system DLL with its own memory management or is using a different API.</p>