Sponsored Content
Top Forums Programming segmantation Fault error SEGV_MAPERR - Address not mapped to object Post 302322800 by pravinbhingare on Thursday 4th of June 2009 03:11:05 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 09:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy