In Debug mode, Visual C++ puts 4 special chars before and after the memory you allocated (0xFD I think), and if it sees that those chars have changed, it knows you wrote past the end (or beginning) of your buffer. If you step through in debug mode and look at the memory address for your pointer you should see something like:
Code:
FD FD FD FD 34 38 54 43 ... FD FD FD FD
If you execute one line at a time and look at the memory after each step, you might see 1 or more of the FD's turn into something else. That would be your bug.