A piece of C++ code I am looking into in VS 2008 has a bad pointer. The pointer is initialized properly and has very few lines of code referencing it. I put a watch on this pointer while debugging.
When a certain method is called, the value of the pointer suddenly changes from 0x05fe0040 “” to 0x00000000 Bad Ptr (in the Watch window of VS2008). I can’t seen to figure out why this is happening. There are no operations on the pointer between the lines of code where it loses its value.
How do I investigate this further? What are some possible reasons why this pointer has turned bad?
I am new to C++ programming and am using VS2008 for the first time, so please explain anything you think is pertinent.
If the value is not changed by any code manipulating the variable, it must be accessed by a stray/dangled pointer or by a buffer/array overflow.
Use a memory breakpoint on the pointer variable, this way the debugger will show you quickly what code is corrupting it.