I have a huge C++ codebase. On a certain set of data there’s a stack overflow. If I run the program under Visual Studio debugger I get a call stack 30 unfamiliar functions deep – one (or more) of those functions created a too big object on stack and this lead to stack exhaustion. I looked at all functions and there’s nothing obvious – nothing like
char buffer[512 * 1024];
I though I could add a variable at the beginning of each of those functions and dump that variable address and recompile and then look at difference between adjacent functions, but that’s lots of manual labor.
How do I quickly identify the function that created a too large set of objects on stack and causes a buffer overflow?
You can use Code Analysis in Visual C++ which is available in higher editions. A warning (C6262) is generated if function uses stack higher than some limit. You may use
/analyze:stacksizeswitch, wherestacksizeis limit you want.