Hi Guys,
I'm getting a segmentation fault in my code and I'm not sure how to fix it. I know where it's occurring, and I know it has something to do with the way I'm using a double pointer, but just have been stuck on what to do. The program is large and the problem hard to explain, so I'm going to try and be as clear as possible and include all necessary pieces of code, however I don't think I can put all of it because it's too big. The problem is occuring in this stretch fo code:
noaMux **nm;
if (searchNoaMuxes(misrChainVector, scopeString, nm))
{
for (int i = (*nm)->getLength()-1; i >= 0; i--)
{
int signalNumberStartIndex, signalNumberEndIndex, signalNumber;
signalNumber = i;
(*nm)->setSignalNumber(i, signalNumber);
getline(*oldVcd, *lineString);
}
}
and here is searchNoaMuxes"
bool searchNoaMuxes(vector<misrChain*> *misrChainVector, string scopeString, noaMux **nm)
{
for (int i = 0; i < misrChainVector->size(); i++)
{
if (misrChainVector->at(i)->findNoaMux(scopeString, nm))
{
cout << "&" << endl;
return true;
}
}
return false;
}
and here is the class with "findNoaMux":
bool findNoaMux(string scopeString, noaMux **nm)
{
for (int i = 0; i < misrs.size(); i++)
{
if (misrs.at(i)->getName() == scopeString)
{
cout << 2 << endl;
cout << "*" << i << "*" << endl;
cout << name << endl;
*nm = misrs.at(i); //SEGMENTATION FAULT
cout << 3 << endl;
return true;
}
}
return false;
}
It's odd because the segmentation fault occurs at the commented line above, but only happens at the end of the foreoop, seemingly after the pointer has already been assigned and the for loop has run every iteration except the last. Does anyone have any idea what is causing this? BTW I allocated all the memory in this method, which is not main, in a block of code that looks like this (except longer):
csib8 = new misrChain("csimisr_b8_counter");
csib8->addNoaMux(new noaMux("/top_tb/mch_imc/umch/usmt/smtcsi1/hctlunit1/hctlnoa1/tlnoafub1/moamux1", 128));
csib8->addNoaMux(new noaMux("/top_tb/mch_imc/umch/usmt/smtcsi1/hctlunit1/hctlnoa1/tlnoafub2/moamux1", 128));
Any help would be appreciated, thanks.
bleh