Solved

buffer overrun?

Posted on 2011-09-21
3
334 Views
Last Modified: 2012-05-12
Hi Experts,

I have a class that contains this member:

vector<CSomeClass> m_Member;

When I look at the address of m_Member before some work is done, and then after, the address is different.  Is there a way to stop execution of whatever thread is currently running as soon as the contents of the address of this member changes?  I noticed there's a new data breakpoint that can be added in VS2010, but it doesn't stop execution when the variable changes - and I don't want control to have to flow over a line that contains that breakpoint- I want that breakpoint to be program-wide.

Thanks for any help!
Mike
0
Comment
Question by:thready
3 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 250 total points
ID: 36578700
You can set conditional break points in Visual Studio's debugger.
http://msdn.microsoft.com/en-us/library/7sye83ce.aspx

When you say the address has changed -- are you sure you're not looking at the internal pointer that the vector is likely to be using to address its internal buffer? This, of course, may change if the internal buffer is re-allocated.
0
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 36581491
to add to above comment:

the address of a member cannot change beside the class object which the member belongs to changes.

class A
{
public:
    std::vector<B> v;
};

void C::f()
{
     // create A object on the heap
     A * pa = new A;   
     // get pointer to vector member of A object pA is pointing to
     std::vector<B> * pabv = &pa->v;
     // the value of pabv pointer now is address of vector member
     pa->v.push_back(B());   
     pabv->resize(10, B());
     // the address of pa->v will not change by operations you do on the vector
     if (&pa->v != pabv)
     {
          // never comes here
     }
     pa = new A;  // create new A 
     // now pa->v has new address cause the A object is not the same as before
}

Open in new window


all other possibilities would mean that memory was corrupted somehow.

Sara
0
 
LVL 1

Author Closing Comment

by:thready
ID: 36926570
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
An API detour question 7 79
Super Scope, DHCP 5 53
passing data from one form to another form in c++ 27 75
Error creating a new C++ project in ,net 20 21
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now