-
February 5th, 2009, 06:53 AM
#1
STL Map : Uninitialized Memory Read
Hi,
This is regarding a problem encountered on executing code developed using VS2005 using C++ Standard Libraries.
I have a member in a class of type std::map. The class definition is indicated below (There are some other class members which I am not indicating here so as to not occupy space)
Code:
class DataHolder
{
private :
map<DWORD, MyClass *> m_MyMap;
public :
DataHolder()
{
m_MyMap.clear();
}
void MyMethod()
{
DWORD j = GetValue();
map<DWORD,MyClass*>::iterator it = m_MyMap.begin();
it = m_MyMap.find(j); //Rational Purifier indicated a problem in this line
if (it == m_MyMap.end())
{
printf("Data has not been found in the map");
}
}
.
.
.
.
.
.
}
When the above class is used in the execution of a program and the Rational Purifier tool is being used to analyze memory issues, the following error was indicated in the line marked above :
"Uninitialized Memory Read "
The next level of instructions displayed by the Rational Purifier editor shows the following
Code:
std::_Tree<class std::_Tmap_traits<unsigned long,class MyClass *,struct std::less<unsigned long>,class std::allocator<struct std::pair<unsigned long const ,class MyClass *> >,0> >::_Lbound(unsigned long const &)const [c:\program files\microsoft visual studio 8\vc\include\xtree.:1174]
_Nodeptr _Wherenode = _Myhead; // end() if search fails
while (!_Isnil(_Pnode))
=> if (_DEBUG_LT_PRED(this->comp, _Key(_Pnode), _Keyval))
_Pnode = _Right(_Pnode); // descend right subtree
else
{ // _Pnode not less than _Keyval, remember it
The problem is indicated in the line shown by "=> " in the snippet above.
Can someone please provide some clues on why this is being indicated and what would be the possible solution.
Last edited by humble_learner; February 5th, 2009 at 06:56 AM.
-
February 5th, 2009, 08:39 AM
#2
Re: STL Map : Uninitialized Memory Read
You've got something else going on. Can you provide a complete compilable example that reproduces the issue?
gg
-
February 5th, 2009, 08:53 AM
#3
Re: STL Map : Uninitialized Memory Read
[ removed duplicate thread ]
-
February 5th, 2009, 02:00 PM
#4
Re: STL Map : Uninitialized Memory Read
I agree with codeplug. That doesn't mean upload an enormous project file. It means upload a program demonstrating the problem that shows how you are using the std::map and perhaps we will notice something that you are doing incorrectly. At the very least, seeing the complete function or class definition might help. If it is really big, just give us a version that compiles with a simple main function.
I noticed that you are calling clear() on the map in the constructor. Why? It hasn't even been filled with anything yet. It is already empty by default. That isn't the problem but just something else that I noticed.
-
February 6th, 2009, 12:08 AM
#5
Re: STL Map : Uninitialized Memory Read
Hello humble_learner
I agree with kempofighter. We need to see SSCE...um..something like that.
The excerpt by itself looks fine. However, calling clear() inside the constructor body seems questionable.
Originally Posted by humble_learner
Code:
DWORD j = GetValue();
That could be the source of the error, what if somehow j is not being assigned? Then calling
Code:
it = m_MyMap.find(j); //Rational Purifier indicated a problem in this line
will cause trouble. Another possible cause is when you assign the iterator to the empty map like you have done below
Code:
map<DWORD,MyClass*>::iterator it = m_MyMap.begin();
If you recall, T.begin() refers to the first element which in this case has no first element. I'm not sure if that's entirely okay or not though (someone correct me for clarity).
hope this helps
-
February 6th, 2009, 04:45 PM
#6
Re: STL Map : Uninitialized Memory Read
Originally Posted by potatoCode
If you recall, T.begin() refers to the first element which in this case has no first element. I'm not sure if that's entirely okay or not though (someone correct me for clarity).
That should be fine. If the map is empty, then the iterator returned by 'begin' will be equal to the iterator returned by 'end'.
Viggy
-
February 6th, 2009, 05:28 PM
#7
Re: STL Map : Uninitialized Memory Read
Originally Posted by MrViggy
That should be fine. If the map is empty, then the iterator returned by 'begin' will be equal to the iterator returned by 'end'.
Viggy
Hello MrViggy,
Aha I see. Thanks for clearing that up for me
bye~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|