In C++, in which way the stack may get corrupted. One way I guess is to overwriting the stack variables by accessing an array beyond its boundaries. Is there any other way that it can get corrupted?
Stack corruption can also be suspected when a passed parameter seems to have a value different from the one passed by the calling function. When a stack corruption is detected, one should look at the local variables in the called and calling functions to look for possible sources of memory corruption.
Pointer variable can point to a invalid memory location which can cause access violation and a crash. Memory corruption may occur because of poor array buffer handling or some abnormal runtime use-cases.
A stack corruption can be caused by buffer overflows on local variables because the return address and data for the calling functions are stored in addresses higher than the addresses for locals.
Heap corruption occurs when a program damages the allocator's view of the heap. The outcome can be relatively benign and cause a memory leak (where some memory isn't returned to the heap and is inaccessible to the program afterward), or it may be fatal and cause a memory fault, usually within the allocator itself.
But those are not particular to C++, which doesn't have any idea of the stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With