segmantation Fault error SEGV_MAPERR - Address not mapped to object


 
Thread Tools Search this Thread
Top Forums Programming segmantation Fault error SEGV_MAPERR - Address not mapped to object
# 1  
Old 06-03-2009
segmantation Fault error SEGV_MAPERR - Address not mapped to object

Program received signal SIGSEGV, Segmentation fault
si_code: 1 - SEGV_MAPERR - Address not mapped to object.
0x9fffffffbe7080d0:0 in free+0xb0 () from /usr/lib/hpux64/libc.so.1


Hi ,

I 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 pointers to strings 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 of the function
:
int CConfigReader::GetConfigValue(char *paramApp,string *ResultServer,string * ResultPort,string *ResultLogDir)
{
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
printf("\n the red is %s \n",buffer);
string *pstrSplit=NULL;
int iNumWords =split(buffer, pstrSplit);
if(iNumWords != -1)
{
if (pstrSplit[0].compare(paramApp)!=0)
{

continue;
}
else
{
*ResultServer=pstrSplit[1];
*ResultPort=pstrSplit[2];
*ResultLogDir=pstrSplit[3];
printf("\n Serve-- %s Port --%s Log Directory --%s \ n",*ResultServer,*ResultPort,*ResultLogDir);
delete[] pstrSplit;
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;
}


function call :
string tempServer;
string tempPort;
string tempLogDir;
// Install the SAP RFC functions that can be called.
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",&tempServer,&tempPort,&tempLogDir))
{
printf("sucessfully executed function \n");
printf("result MMSYNCH server is--> %s Port is --> %s log dir is -->%s \n",tempServer,tempPort,tempLogDir);
nPort=atoi(tempPort.c_str());
strcpy(szServer, tempServer.c_str());
strcpy(szLogDir, tempLogDir.c_str());

}
else
{
ErrorExit( table[0].ithandle, "Error in reading config file", errno);
}


Please help me in resolviong this error .
# 2  
Old 06-04-2009
Code tags for code please. They make it readable. [ code ] stuff [ /code ] without the extra spaces in the tags.

Posting a member function out of context is pretty pointless since a class is bound to contain member variables of which we have no knowledge, could you please post the complete code for this class, including header, in code tags?

Compiling your executable with debugging support, and running it in a debugger, may tell you what line this segfault is happening on. The gcc flag for this is -ggdb, and the GNU tool for debugging is gdb, I am not certain what HP-UX specific tools there are for this.
# 3  
Old 06-04-2009
Thanks for reply .
I have changed parametrs to this function from string * to char *
getConfigValue is function in class CConfigReader
Code:
CConfigReader .c
 
#include "CConfigReader.h"
using namespace std;
CConfigReader::CConfigReader()
{}
CConfigReader::CConfigReader(char *paramConfigpath)
{
memset(szConfigPath, ' ', sizeof( szConfigPath) );
memcpy(szConfigPath,paramConfigpath,sizeof( szConfigPath));
}
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
{

strcpy(ResultValue,pstrSplit[paramKey].c_str()); 
break;
}
}
else
{
cout << "Error in reading the line "<<endl;
return 1;
}

}
else
{
cout << "header line ignore it "<<endl;

}
}
else
{
cout << "empty line ignore it "<<endl;
}
}//end of while 
}
else
{
cout << "unable to open the stream ";
return 1;
}
Stream.close();
return 0; 
}
int CConfigReader::split(string strInput, string *&pstrResult)
{
// Reserve some memory, WATCH OUT! USER NEEDS TO FREE THE MEMORY!
if(pstrResult != NULL)
return -1; // We need a clean buffer, we could shoose to delete the inside,
else
pstrResult = new string[1];
string strTemp;
int iInputLen = strInput.length(), iNumWords = 0;
if(iInputLen)
{
for(int i = 0; i < iInputLen; i++)
{
if((strInput[i] == ' ') && (!strTemp.empty())) // Split it if there is a word.
{
if(iNumWords > 0)
{
string *pstrTempRes = new string[iNumWords];
CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
delete[] pstrResult;
pstrResult = new string[iNumWords+1];
CopyBuffer(pstrResult, pstrTempRes, iNumWords);
pstrResult[iNumWords] = strTemp;
delete[] pstrTempRes;
iNumWords++;
}
else
{
pstrResult[iNumWords] = strTemp;
iNumWords++;
}
strTemp.erase(); //- Erase the temp-string, and start over.
i++; // SKIP THE SPACE!
}
strTemp += strInput[i];
}
if(strTemp.length() > 0)
{
if(iNumWords > 0)
{
string *pstrTempRes = new string[iNumWords];
CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
delete[] pstrResult;
pstrResult = new string[iNumWords+1];
CopyBuffer(pstrResult, pstrTempRes, iNumWords);
pstrResult[iNumWords] = strTemp;
delete[] pstrTempRes;
iNumWords++;
}
else
{
pstrResult[iNumWords] = strTemp;
iNumWords++;
}
}
}
return iNumWords;
}
void CConfigReader::CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen)
{
for(int i = 0; i < iDynamicLen; i++)
 
{
pstrDest[i] = pstrSource[i];
}
}

Code:
CConfigReader.h
 
#include <iostream>
#include <istream>
#include <fstream>
#include <istream>
#include <string>
#include <stdio.h>
using namespace std;
class CConfigReader
{
public:
char szConfigPath[100];
CConfigReader();
CConfigReader(char *paramConfigpath );
int GetConfigValue(char *paramApp,int paramKey,char *ResultValue);
private:
int split(string strInput, string *&pstrResult);
void CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen);
};

function call is as folllows
Code:
char szLogDir[ MAX_PATH ];
enum AppConfig {AppName=0,Server,Port,LogDir};
 
AppConfig enLogDir=LogDir;
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",enLogDir,szLogDir))
{
printf("sucessfully executed function \n");

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

Thanks
# 4  
Old 06-04-2009
Code:
CConfigReader .c
 
#include "CConfigReader.h"
using namespace std;
CConfigReader::CConfigReader()
{}

CConfigReader::CConfigReader(char *paramConfigpath)
{
  memset(szConfigPath, ' ', sizeof( szConfigPath) );
  memcpy(szConfigPath,paramConfigpath,sizeof( szConfigPath));
}
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
            {
              strcpy(ResultValue,pstrSplit[paramKey].c_str()); 
              break;
            }
          }
          else
          {
            cout << "Error in reading the line "<<endl;
            return 1;
          }
        }
        else
        {
          cout << "header line ignore it "<<endl;
        }
      }
      else
      {
        cout << "empty line ignore it "<<endl;
      }
    }//end of while 
  }
  else
  {
    cout << "unable to open the stream ";
    return 1;
  }

  Stream.close();
  return 0; 
}

int CConfigReader::split(string strInput, string *&pstrResult)
{
  // Reserve some memory, WATCH OUT! USER NEEDS TO FREE THE MEMORY!
  if(pstrResult != NULL)
    return -1; // We need a clean buffer, we could shoose to delete the inside,
  else
    pstrResult = new string[1];

  string strTemp;
  int iInputLen = strInput.length(), iNumWords = 0;

  if(iInputLen)
  {
    for(int i = 0; i < iInputLen; i++)
    {
      if((strInput[i] == ' ') && (!strTemp.empty())) // Split it if there is a word.
      {
        if(iNumWords > 0)
        {
          string *pstrTempRes = new string[iNumWords];
          CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
          delete[] pstrResult;
          pstrResult = new string[iNumWords+1];
          CopyBuffer(pstrResult, pstrTempRes, iNumWords);
          pstrResult[iNumWords] = strTemp;
          delete[] pstrTempRes;
          iNumWords++;
        }
        else
        {
          pstrResult[iNumWords] = strTemp;
          iNumWords++;
        }

        strTemp.erase(); //- Erase the temp-string, and start over.
        i++; // SKIP THE SPACE!
      }

      strTemp += strInput[i];
    }

    if(strTemp.length() > 0)
    {
      if(iNumWords > 0)
      {
        string *pstrTempRes = new string[iNumWords];
        CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
        delete[] pstrResult;
        pstrResult = new string[iNumWords+1];
        CopyBuffer(pstrResult, pstrTempRes, iNumWords);
        pstrResult[iNumWords] = strTemp;
        delete[] pstrTempRes;
        iNumWords++;
      }
      else
      {
        pstrResult[iNumWords] = strTemp;
        iNumWords++;
      }
    }
  }
  return iNumWords;
}

void CConfigReader::CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen)
{
  for(int i = 0; i < iDynamicLen; i++)
  {
    pstrDest[i] = pstrSource[i];
  }
}

Code:
CConfigReader.h
 
#include <iostream>
#include <istream>
#include <fstream>
#include <istream>
#include <string>
#include <stdio.h>

using namespace std;

class CConfigReader
{
public:
  char szConfigPath[100];
  CConfigReader();
  CConfigReader(char *paramConfigpath );
  int GetConfigValue(char *paramApp,int paramKey,char *ResultValue);
private:
  int split(string strInput, string *&pstrResult);
  void CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen);
};

function call is as folllows
Code:
char szLogDir[ MAX_PATH ];
enum AppConfig {AppName=0,Server,Port,LogDir};
 
AppConfig enLogDir=LogDir;
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",enLogDir,szLogDir))
{
  printf("sucessfully executed function \n");
}
else
{ 
  printf("Error in reading the file \n" );
  exit ;
}

I'll take a closer look at this in a bit, had to fix the indentation first.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to initialize an object with another object of different class?

How to initialize an object of class say "A", with an object of type say "B". The following code give the error message "error: conversion from âAâ to non-scalar type âBâ requested" #include <iostream> using namespace std; class B; class A{ public: A() { cout <<"\nA()" << endl; } ... (1 Reply)
Discussion started by: techmonk
1 Replies

2. Red Hat

Object not found error for mediawiki

Hi All, I am new to linux and trying to install mediawiki on linux server. I have installed xampp and mediawiki on window which works absolutely fine. The redhat version i am using seems pretty old 5.1. Here is what I did so far on redhat to install mediawiki 1. installed xampp for... (0 Replies)
Discussion started by: Puvi
0 Replies

3. Programming

Signal SEGV (no mapping at the fault address) in _memcpy at 0xff0b07c0

Hi, I am unable to copy the cursor value into character variable which is defined in nested structure by pointer. typedef struct aaa { unsigned char device_type; unsigned char encrypt; unsigned short rec_len; } ABC; typedef ABC *Pabc; typedef struct def { ABC... (9 Replies)
Discussion started by: gthangav
9 Replies

4. UNIX for Dummies Questions & Answers

signal SEGV (no mapping at the fault address)

Hello i ve got the following error on a C servor. signal SEGV (no mapping at the fault address) when running in dbx program terminated by signal SEGV (no mapping at the fault address) 0xff1d5cb4: srch_dir+0x0154: cmp %o1, %o0 Current function is _log 533 ... (4 Replies)
Discussion started by: mumuri
4 Replies

5. Programming

help with C++ code that relate the object with physical address

I need some help to write a C++ code that read and write the register of a sequencer. I have to make a code that relate the objects with the physical address but I am a bit confuse. Could someone suggest me how to proceed? in which parts do I split the code? thanks (1 Reply)
Discussion started by: silviafisica
1 Replies

6. UNIX for Dummies Questions & Answers

Object reference not set to an instance of an object

I am new to PHP and UNIX. I am using Apache to do my testing on a Windows Vista machine. I am getting this error when I am trying to connect to a web service. I did a search and did not see any posts that pertain to this. Here is my function: <?php function TRECSend($a, $b, $c, $d,... (0 Replies)
Discussion started by: EddiRae
0 Replies

7. UNIX for Dummies Questions & Answers

Panic kernal-mode address fault on user address 0x14

:) Firstly Hi all!!, im NEW!! and on here hoping that someone might be able to offer me some help... i have a server that keeps crashing every few days with the error message: PANIC KERNAL-MODE ADDRESS FAULT ON USER ADDRESS 0X14 KERNAL PAGE FAULT FROM (CS:EIP)=(100:EF71B5BD) EAX=EF822000... (10 Replies)
Discussion started by: Twix
10 Replies

8. Linux

Error Mismatched object file

Dear All, Need your help to rectify this error. Recently I have upgraded my Linux server from 32 bit to 64 bit server. OS details are Red Hat Enterprise Linux Server release 5.3 Kernel 2.6.18-120.el5 on an x86_64 After upgradation, when i try to compile or catalog any program, it is... (2 Replies)
Discussion started by: mysmileforu
2 Replies

9. UNIX for Dummies Questions & Answers

signal SEGV (no mapping at the fault address) in _malloc_unlocked at 0xfe1d44ac

When i run a program in sun solaris i got core dumped with an error message as follows... signal SEGV (no mapping at the fault address) in _malloc_unlocked at 0xfe1d44ac 0xfe1d44ac: _malloc_unlocked+0x022c: ld , %o3 Current function is GetEDBInfo 360 EXEC SQL (dbx) where... (1 Reply)
Discussion started by: noufal
1 Replies

10. Programming

Object File Error

Hi, I've tried to compile a program I wrote with a Makefile, yet it returns an error: <<<test_log>>> itest_log.o /sr/local/bin/gcc -o test_log.o -I ../../../include -L ../../../lib -llog_mgr sh: itest_log.o: execute permission denied Error code 1 make: Fatal error: Command failed for... (3 Replies)
Discussion started by: Stevhp
3 Replies
Login or Register to Ask a Question