• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

buffer overrun?

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!
2 Solutions
evilrixSenior Software Engineer (Avast)Commented:
You can set conditional break points in Visual Studio's debugger.

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.
to add to above comment:

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

class A
    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
     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.

threadyAuthor Commented:
Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now