General
cancel
Showing results for 
Search instead for 
Did you mean: 

Segmentation fault address not mapped to object error

SOLVED
Go to solution
Segmentation Error
Occasional Visitor

Segmentation fault address not mapped to object error

Hi ,
have developed a class to read config file (flat file with space as a field seperator ) on plattform HP-UX B.11.23 IA 64 .

I am passing char arrays to a function which reads the config file and traverse line by line and retrieves value on the basis of key passed as parameter . I am getting above error .when i call this function more than once. First time call works fine but second time it fails with above error.

please see code for function
int CConfigReader::GetConfigValue(char *paramApp,int paramKey,char *ResultValue)
{
ifstream Stream (szConfigPath);

if (Stream.is_open())
{
while(!Stream.eof())
{
string buffer=NULL;
getline(Stream, buffer);
if(buffer.length() !=0)
{
if (buffer.find('#') == string::npos)
{
//ingnore the line header
string *pstrSplit=NULL;
int iNumWords =split(buffer, pstrSplit);
if(iNumWords != -1)
{
if (pstrSplit[0].compare(paramApp)!=0)
{

continue;
}
else
{
printf("Line read is %s \n",buffer);
printf("Result is %s \n",pstrSplit[paramKey]);
strcpy(ResultValue,pstrSplit[paramKey].c_str());
break;
}
}
else
{
cout << "Error in reading the line "< return 1;
}

}
else
{
cout << "header line ignore it "<
}
}
else
{
cout << "empty line ignore it "< }
}//end of while
}
else
{
cout << "unable to open the stream ";
return 1;
}
Stream.close();
return 0;
}

Please help me to sort out this error .
5 REPLIES
Dennis Handly
Acclaimed Contributor

Re: Segmentation fault address not mapped to object error

>I am passing char arrays to a function

Is ResultValue big enough?

>but second time it fails with above error.

Do you have a stack trace? Have you compiled with -g to debug it?

>string buffer=NULL;

No need to use "=NULL". string has a default constructor.

>printf("Line read is %s \n",buffer);

This should be:
printf("Line read is %s\n", buffer.c_str());





Segmentation Error
Occasional Visitor

Re: Segmentation fault address not mapped to object error

Thanks for reply Dennis .

PLease find follwing details

1)Is ResultValue big enough?

I am calling this function as below :
[code]
char szLogDir[256 ];///global variable
//or char szLogDir[MAX_PATH];
enum AppConfig {AppName=0,Server,Port,LogDir};
AppConfig enLogDir=LogDir;
CConfigReader config=CConfigReader(szConfigFile);
if (!config.GetConfigValue"SETTINGS",enLogDir,szLogDir))
{

printf("Log Directory read from config file successfully \n");

}
else
{
printf("Error in reading the config file while reading Log directory \n" );
exit ;
}



[\code]


The trget array has size 256 and source size is 20 .


2) Yeah I have compiled this code with -g and i get following message/error

si_code: 1 - SEGV_MAPERR - Address not mapped to object.
0x9fffffffbf544560:0 in pthread_mutex_destroy+0xc0 ()
from /usr/lib/hpux64/libpthread.so.1


Please let me know if you need any more input .

Thanks in advance .
Dennis Handly
Acclaimed Contributor

Re: Segmentation fault address not mapped to object error

>2) Yeah I have compiled this code with -g and I get following message/error
si_code: 1 - SEGV_MAPERR - Address not mapped to object.
0x9fffffffbf544560:0 in pthread_mutex_destroy+0xc0 libpthread.so.1

>Please let me know if you need any more input.

The rest of the whole stack trace.

Have you compiled everything with -mt?
Segmentation Error
Occasional Visitor

Re: Segmentation fault address not mapped to object error

Hi dennis , today I compiled it with -mt and its working fine ..

Thanks you very much ..
Dennis Handly
Acclaimed Contributor
Solution

Re: Segmentation fault address not mapped to object error

>I compiled it with -mt and its working fine

If you are happy with your answers, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33