Sign in to follow this  

buffer overwrite debugging in VC++

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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_range
template<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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ok, I did the watch variable and found the lines that make the problem, they are:


m_vCollisions[i].Body1->m_MyState.AngularVelocity +=
(Impulse/state_a.MomentOfInertia)*(R_ap.Dot(Normal));
m_vCollisions[i].Body2->m_MyState.AngularVelocity -=
(Impulse/state_b.MomentOfInertia)*(R_bp.Dot(Normal));



could that cause a problem?
Thanks.

Share this post


Link to post
Share on other sites
Well, the obvious questions are:
  • Is i within permitted index values?
  • Does content of the array at index i have a valid Body1 pointer to an existing object?

    Share this post


    Link to post
    Share on other sites
    -yes
    -yes

    I still can't figure out what the problem is:(
    When it gets to th\t line it doesn't always crash, it seems to crash sort of randomly. What could this mean?
    Thanks.

    Share this post


    Link to post
    Share on other sites
    What version of VC++ are you using? VC2005's STL implementation will break to the debugger if you access an invalid location in the vector, which pre-VC2005 STL implementations don't do.

    It's usually impossible to tell if one line of code is going to cause a problem, it like saying "Have I used to correct version of the word 'there'?" - It's absolutely impossible to tell without some sort of context.

    Share this post


    Link to post
    Share on other sites
    I'm using Express - 2005. I got this on msdn:
    Quote:

    To use the debug build to check for memory overwrite, you must first rebuild your project for debug. Then, go to the very beginning of your application's InitInstance function and add the following line:

    afxMemDF |= checkAlwaysMemDF;


    What is the InitInstance function and were do I find it?
    Thanks.

    Share this post


    Link to post
    Share on other sites

    This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

    If you intended to correct an error in the post then please contact us.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this