Visual C ++: Invalid selection size. How to make the debugger stop on this message?

The MFC program that I am debugging prints this message in the Exit window in Visual Studio 9.0:

HEAP[AppName.exe]: Invalid allocation size - 99999998 (exceeded 7ffdefff)

I am sure that this is due to a bad "new", uninitialized variable or similar error.

The question arises: how do I get the debugger to stop on this message so that I can view the stack trace and solve the problem?


Edit: The following snippets do not give the same warning. Instead, they create a style message Invalid allocation size: 4294967295 bytes..

int stupid = -1;
char *bob = new char[stupid];

and

malloc(-1);

So, I suspect that this comes from a system DLL with its own memory management or uses a different API.

+3
4

, , HeapAlloc() ntdll.dll.

:

HANDLE hHeap = HeapCreate(0, 0, 4096);
LPVOID p = HeapAlloc(hHeap, 0, 0x99999998);

DbgPrint() ntdll.dll, ( , , ) .

+4

409 dbgheap.c, Program Files\Microsoft Visual Studio 9.0\VC\crt\src. .

+1

:

Debug -> Exceptions. C++-Exception std::bad_alloc Thrown, , .

0

, , , ? Grep . / Debug- > New breakpoint.

, ( ) , ( - .cpp ). :

__asm {
    int 3;
}

to manually insert the "break into debugger" operation code. This is a trick that I often use to force a breakpoint in a dll for which the debugger could not correctly locate the breakpoint.

0
source

Source: https://habr.com/ru/post/1748401/


All Articles