buffer overwrite debugging in VC++

Started by
14 comments, last by daniel_i_l 17 years, 8 months ago
Hi, i noticed that sometimes one of the variables that I'm printing out gets a value of something like #FD. i think that this means that I'm over writing something and it's flowing into my var - is this right? How do i debug this in VC++? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
Set a watch on the variable. It will interrupt execution whenever its value is changed, and pinpoint the code where the change is performed.
Ok, the debugger said that I got an access violation and stopped at this code from the stl code:
inline void __CLR_OR_THIS_CALL _Container_base::_Orphan_all() const	{	// orphan all iterators	_Lockit _Lock(_LOCK_DEBUG);	if (_Myfirstiter != _IGNORE_MYITERLIST)		{		for (_Iterator_base **_Pnext = (_Iterator_base **)&_Myfirstiter;			*_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)			(*_Pnext)->_Mycont = 0;		*(_Iterator_base **)&_Myfirstiter = 0;		}	}


I did it again and it was here:
		// TEMPLATE FUNCTION _Destroy_rangetemplate<class _Ty,	class _Alloc> inline	void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)	{	// destroy [_First, _Last)	_Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));	}

what does this mean?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
This means you are using a deallocated variable, which is a bad thing.
What does that mean? What is "using a deallocated variable"?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
This means that the area of memory that you use does not belong to you. Either you have a pointer that points to somewhere it shouldn't, or you allocated memory, used it, deallocated it and used it again (either with new, or as part of a container).

Of course, there is still the probability that you have a non-deterministic bug in your code that randomly bombs areas of memory through overflows. Did you do that watch thing I told you about?
Thanks, how do you set a watch on a variable without setting a breakpoint?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Check your debugger documentation for this — I don't even know what debugger you are using, there's no way I could tell you that.
the standard VC++ debugger.
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Place a breakpoint when the variable is created, select the variable name in the code, right-click and choose to watch it. Remove the program and resume the running.

You might need to evaluate the address of the variable, and watch the contents at that adress instead.

This topic is closed to new replies.

Advertisement