Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

STL pair declaration is causing memory access error

807575Jul 21 2009 — edited Jul 27 2009
I am working on Solaris 8, Sun C++ 5.3 compiler and dbx 6.2. dbx is showing memory access error at following line:_
virtual int insert( keyType1_t keyVal, dataType1_t& info_t) >>>>    {
>>>>
 pair<map<keyType1_t,dataType1_t>::iterator,bool> 
retItor;"
{code} 

_*Code is as follows:*_
{code}
#include<iostream>
#include<map>
using namespace std;

struct MsgS
{
unsigned long key;
int element;
};

template<class keyType_t, class dataType_t>
class AbsC
{
public:
AbsC();
AbsC( keyType_t, dataType_t );
virtual int insert( keyType_t, dataType_t& ) = 0 ;
virtual int remove( keyType_t, dataType_t* ) = 0 ;
virtual int search( keyType_t, dataType_t* ) = 0 ;
~AbsC();

protected:
keyType_t keyValue;
dataType_t info;

};

template<class keyType1_t, class dataType1_t>
class WrapperC : public AbsC<keyType1_t, dataType1_t> 
{

protected:
map<keyType1_t, dataType1_t> InfoMap_obj;
typedef map<keyType1_t, dataType1_t> InfoMap;
typename typedef map<keyType1_t, dataType1_t>::iterator InfoMap_itor;
typedef typename pair<typename map<keyType1_t,dataType1_t>::iterator,bool> InfoMap_pairItor;
public:
WrapperC( keyType1_t arg1, dataType1_t arg2) ;

virtual int insert( keyType1_t keyVal, dataType1_t& info_t) 
{
pair<map<keyType1_t,dataType1_t>::iterator,bool> retItor;
retItor = InfoMap_obj.insert( pair<keyType1_t, dataType1_t>(keyVal, info_t ) );

if ( retItor.second == false )
{
cout<<"\n Element alread exists";
return (-1);
}
return (1);
};

virtual int remove( keyType1_t keyVal, dataType1_t* info_tp) 
{
InfoMap_itor retItor;
retItor =  InfoMap_obj.find(keyVal) ;
if(retItor == InfoMap_obj.end())
{
cout <<"\n key not found";
info_tp = NULL;
return (-1);
}
*info_tp = retItor->second;
InfoMap_obj.erase( InfoMap_obj.find(keyVal) );
return (1);
};

virtual int search( keyType1_t keyVal, dataType1_t* info_tp) 
{
//dataType_t infoRet;
InfoMap_itor retItor;
retItor = InfoMap_obj.find( keyVal );
if(retItor == InfoMap_obj.end() )
{
cout<<"\n key not found";
cout << endl << "search key: \"" << keyVal << "\"" << endl;
//displayDataFrom();
info_tp = NULL;
return ( -1 );
}
*info_tp = retItor->second;
return( 1 );
};
~WrapperC(){};

//Copy constructor 
WrapperC( const WrapperC& mapWrapper_o )
{
if( &mapWrapper_o != NULL ) 
{
this->subsInfoMap_obj = mapWrapper_o.InfoMap_obj ;
}
};
//Assignment Operator Overlaoding
WrapperC& operator= ( const WrapperC& mapWrapper_o )
{
if( ( this != &mapWrapper_o ) && ( &mapWrapper_o != NULL ) )
{
this->InfoMap_obj = mapWrapper_o.InfoMap_obj ;
this->noOfElem_ul = mapWrapper_o.noOfElem_ul ;
}
return ( *this ) ;
};
};

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::AbsC()
{
}

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::AbsC( keyType_t argkeyValue, dataType_t info_t)
{
info = info_t;
keyValue = argkeyValue;
}

template<class keyType_t, class dataType_t>
AbsC<keyType_t, dataType_t>::~AbsC()
{
}

template<class keyType1_t, class dataType1_t>
WrapperC<keyType1_t, dataType1_t>::WrapperC( keyType1_t key_t, dataType1_t info_t):AbsC( key_t, info_t)
{
}

int main()
{
struct MsgS msgS;
struct MsgS* msgR;
msgR = new struct MsgS;
msgS.key = 123456;
msgS.element = 1;
WrapperC<unsigned long, struct MsgS> objS(msgS.key, msgS);
int b = objS.insert( msgS.key, msgS);
//int b = objS.insert( msgS.key, msgS.key);
// adding 2 element
msgS.key = 123454;
msgS.element = 2;
b = objS.insert( msgS.key, msgS);
//remove elem
b = objS.remove(12, msgR);
if ( b == 1 )
cout<<"\n ret value for remove elem "<<msgR->key << "\t" << msgR->element<<endl;
b = objS.remove(123456, msgR);
if ( b == 1 )
cout<<"\n ret value for remove elem "<<msgR->key << "\t" << msgR->element<<endl;
b = objS.search(78912, msgR);
if ( b ==1 )
cout<<"\n ret value for search elem "<<msgR->key << "\t" << msgR->element<<"\n";
b = objS.search(123454, msgR);
if ( b == 1 )
cout<<"\n ret value for search elem "<<msgR->key << "\t" << msgR->element<<endl;
return 1;
}
[
|http://forums.sun.com/codeSnippetPopup.jsp?csid=362232]
[
|javascript:selectElementById('codeSnippet362232');]{code}          

_*dbx report
Attempting to read 4 bytes at address 
0xffbee8c8
which is 192 bytes above the current stack pointer
=>[1] 
__rwstd::__rb_tree<unsigned long,std::pair<const unsigned 
long,MsgS>,__rwstd::__select1st<std:
:pair<const unsigned 
long,MsgS>,unsigned long>,std::less<unsigned 
long>,std::allocator<std::pair<con
st unsigned long,MsgS> 
::iterator::iterator(0xffbee93c, 0xffbee8c8, 0x2, 0xfb8,
0xfe960c00, 0xff8 ), at 0x305f4 [2] std::pair<__rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__sele ct1st<std::pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std ::pair<const unsigned long,MsgS>
::iterator,bool>::pair(this = 0xffbee93c), line 106 in
"utility" [3] WrapperC<unsigned long,MsgS>::insert(this = 0xffbeea0c, keyVal = 123456U, info_t = STRUCT), li ne 42 in "sample.cc" [4] main(), line 138 in "sample.cc" <rtc> Read from uninitialized (rui): Attempting to read 4 bytes at address 0xffbee8c8 which is 192 bytes above the current stack pointer =>[1] __rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__select1st<std: :pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std::pair<con st unsigned long,MsgS>
::iterator::iterator(0xffbee93c, 0xffbee8c8, 0x2, 0xfb8,
0xfe960c00, 0xff8 ), at 0x305f4 [2] std::pair<__rwstd::__rb_tree<unsigned long,std::pair<const unsigned long,MsgS>,__rwstd::__sele ct1st<std::pair<const unsigned long,MsgS>,unsigned long>,std::less<unsigned long>,std::allocator<std ::pair<const unsigned long,MsgS>
::iterator,bool>::pair(this = 0xffbee93c), line 106 in
"utility" [3] WrapperC<unsigned long,MsgS>::insert(this = 0xffbeea0c, keyVal = 123454U, info_t = STRUCT), li ne 42 in "sample.cc" [4] main(), line 143 in "sample.cc" I wonder whether it is false positive. -Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 24 2009
Added on Jul 21 2009
7 comments
104 views