I have this vector of pointers
std::vector<Connection *> List;
typedef struct {
int Initialized;
....
} Connection;
My program is core dumping somewhere in these 5 lines. What could be the problem?
1 for ( size_t i = 0; i < List.size(); i++ ) {
2 if ( List[i]->Initialized ) {
3 counter++ ;
4 }
5} /* for() */`
List[i]
is pointing to some garbage location. so when you access List[i]->Initialized, it core dumps. Can I check forNULL
here to prevent the core dump? My understanding is checking forNULL
will not work as the pointer can be pointing to garbage and still be valid. So can I add some check before line 2 here, to prevent the core dump?The
List.size()
has a huge number,so the for loop never ends??
Am I missing some other scenarios here? we don't know what is causing this issue, so can't reproduce it. For some reason I am unable to use gdb or dbx on this system.