Hi,
I am working on a project and when I run my code, I get a segfault. I checked it with valgrind, and it says that I am trying to access a memory location that I maybe not malloc'd, stack'd or recently free'd. The only 'mysterious' thing I'm doing is, passing the pointer of a structure list to a function. Here is the code I get the segfault.
int GetFieldInt(list<fieldInfo> *listIn)
{
list<fieldInfo>::iterator tempItr;
int listCount = 0;
tempItr = (*listIn).begin();
while(tempItr != (*listIn).end())
{
listCount++;
(*tempItr).percentage = ((*tempItr).percentage)*targetCount/100; //segfault here
tempItr++;
}
if(listCount == 0)
{
cout<<"Field not defined!\n";
return -1;
}
else
return (int)MAX_RAND/listCount;
}
It's a rather long code. Whenever I pass the list pointer to a function, funny things happen. Sometimes, in the linux terminal, the font changes to some weird symbols. Can anyone help me with this?
Your help is much appreciated. Thanks in advance.
Thilan