Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

getting segmentation fault error in C++

Vaibhav GuptaVaibhav Gupta bangaloreMember Posts: 1

getting segmentation fault in C++ code
I am new to c++, working on my company's assignment my c++ code is giving me segmentation fault error, even debug is not detecting the exact error, please help me in this.

FetchingAndSortingFiles.h

FetchingAndSortingFiles *fileParamToSort;
std::vector l_vecOfFileSortingOrderValues;
ABL_String m_lobName; //ABL_String is defined in framework ,it's just std::string
ABL_String m_CategoryName;
ABL_String m_langName;
ABL_String m_filename;
int m_numOfPages;
unsigned int m_parentAccountCode;
unsigned int m_childAccountCode;
unsigned int m_postalCode;
ABL_String filename;
ABL_String m_dirname;
std::vector l_unsortedFileList;

FetchingAndSortingFiles.cpp

//mb_process() I am calling from main function from another file.
bool FetchingAndSortingFiles::mb_process()
{
// in below function I am fetching 3 files GSM_GOVT_ALL_12341_4158_103.ps, GSM_GOVT_ALL_12342_106563_101.ps ,GSM_GOVT_ALL_12342_4185_103.ps and storing in l_unsortedFileList vector

m_ABL_DirectoryReader.mb_listDir(l_unsortedFileList,concatPathString.c_str(),m_searchOptn,false);

std::cout<<"l_unsortedFileListSize======="<<l_unsortedFileList.size()<<std::endl; //giving size 3

// allocating the memory equivalent to the size of vector,i think here i am committing the some mistake
fileParamToSort=new FetchingAndSortingFiles[l_unsortedFileList.size()];
for (int m_ifileIndex = 0; m_ifileIndex < l_unsortedFileList.size(); m_ifileIndex++)
{
filename =(l_unsortedFileList[m_ifileIndex]);
std::cout<<" filename====="<< filename<<std::endl; //giving first file which is GSM_GOVT_ALL_12341_4158_103.ps
//in below function mb_extractDelimitedValues I am taking file one by one and segregating them based on delimiter ''
for example- if i take first file GSM_GOVT_ALL_12341_4158_103 then segregating them through delimeter '
' and then storing GSM ,GOVT ,ALL, 12341,4158,103 in vector l_vecOfFileSortingOrderValues like below
l_vecOfFileSortingOrderValues = FetchingAndSortingFiles::mb_extractDelimitedValues(filename,'_');
//in below code i am retreiving the values GSM ,GOVT ,ALL, 12341,4158,103 and so on from vector and storing them in fileParamToSort pointer ,m_direcDate,numOfPages values i am getting from another functions
if (l_vecOfFileSortingOrderValues.size() ==6)
{
fileParamToSort[m_ifileIndex].m_lobName = l_vecOfFileSortingOrderValues[0].mb_getSTLString();
fileParamToSort[m_ifileIndex].m_CategoryName = l_vecOfFileSortingOrderValues[1].mb_getSTLString();
fileParamToSort[m_ifileIndex].m_langName = l_vecOfFileSortingOrderValues[2].mb_getSTLString();
fileParamToSort[m_ifileIndex].m_parentAccountCode =atoi(( l_vecOfFileSortingOrderValues[3].mb_getSTLString()).c_str());
fileParamToSort[m_ifileIndex].m_childAccountCode = atoi((l_vecOfFileSortingOrderValues[4].mb_getSTLString()).c_str());
fileParamToSort[m_ifileIndex].m_postalCode = atoi((l_vecOfFileSortingOrderValues[5].mb_getSTLString()).c_str());
fileParamToSort[m_ifileIndex].m_numOfPages =numOfPages;
fileParamToSort[m_ifileIndex].m_filename=filename;
fileParamToSort[m_ifileIndex].m_dirname=m_direcDate;
}

else
{
*m_ABL_ServicePtr<< DEBUG <<"file "<<filename<<"is not in correct format"<<Endl;
delete [] fileParamToSort;
return false;
}
}//for loop ends

in destructor in same file

FetchingAndSortingFiles::~FetchingAndSortingFiles()
{
std::cout<<"fileParamToSort======="<<fileParamToSort<<std::endl;
if(fileParamToSort){
delete [] fileParamToSort;
}
fileParamToSort=NULL;
}

Output:

fileParamToSort=======0x196afe8
Segmentation fault (core dumped)

Tagged:
Sign In or Register to comment.