Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the symptoms of a stack overflow in a C++ program?

I just ran into an issue where a stack overflow in a threaded c++ program on HPUX caused a SEGV_MAPERR when a local object tried to call a very simple procedure. I was puzzled for a while, but luckily I talked to someone who recognized this as a stack size issue and we were able to fix the problem by increasing the stack size available to the threads.

How can I recognize when the stack overflows? Do the symptoms differ on windows/linux/hpux?

like image 463
Plasmer Avatar asked Feb 18 '09 21:02

Plasmer


1 Answers

Assuming you're not on a platform thats going to stop your app and say "stack overflow" I suspect you'll see the same behavior that you would see from any kind of buffer overflow. The stack is just another preallocated chunk of memory for your program, and if you go outside those bounds... well good luck! Who knows what you'll stomp on!

You could write over the temperature readout from the CPU, it could be the email you're typing to Larry, it could be the bit saying that the kernel is locked, causing a fun deadlock condition! Who knows.

As for C++, there's nothing saying how the stack should be laid out in relation to other things in memory or that this thing even needs to be a stack!

like image 99
Doug T. Avatar answered Nov 14 '22 23:11

Doug T.