|
From: Ioannis V. <iv...@em...> - 2003-07-09 22:41:15
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Shane =
Bryldt
Sent: Thursday, July 10, 2003 12:54 AM
To: C++
Subject: [Dev-C++] STL Map question
Hello,
=20
I recently ran into an issue that I can't seem to pinpoint the cause =
of.
99% of the time, it seems to work, so it seems to be a small situational
bug. Subject, is a UserList class, which internally implements an STL =
map.
I am not sure why, but it seems to crash occasionally when I attempt to =
call
the map::find function, with a valid null terminated char array. The =
map
template implements a simple case insensative comparison. As I said, it
works more often than not, but for some reason when attempting to delete
from the list sometimes, it causes a SEGFAULT. Here is what GDB has to =
say:
=20
Program received signal SIGSEGV, Segmentation fault.
0x80bb142 in _Rb_tree<char const *, pair<char const *const, User *>,
_Select1st<pair<char const *const, User *> >, UserList::ltstr,
allocator<User *> >::find (
this=3D0xbf14b30, __k=3D@0xbfbff7bc) at =
/usr/include/g++/stl_tree.h:1118
1118 _Link_type __x =3D _M_root(); // Current node.=20
(gdb) up
#1 0x80bb529 in map<char const *, User *, UserList::ltstr, =
allocator<User
*> >::find (this=3D0xbf14b30, __x=3D@0xbfbff7bc) at
/usr/include/g++/stl_map.h:187
187 iterator find(const key_type& __x) { return _M_t.find(__x); }
(gdb) up
#2 0x80ba8e9 in UserList::DeleteUser (this=3D0xbf14b30,=20
pNick=3D0xbf12300 "_=C7=E1=DF=D1=D2_") at UserList.cpp:26
26 UserMap::iterator it =3D m_mapUsers.find(pNick);
(gdb) print pNick
$1 =3D 0xbf12300 "_=C7=E1=DF=D1=D2_"
=20
=20
And here is the code in question.
=20
bool UserList::DeleteUser(const char *pNick)
{
bool bRet =3D false;
=20
if(m_mapUsers.size() > 0)
{
UserMap::iterator it =3D m_mapUsers.find(pNick);
if(it !=3D m_mapUsers.end())
{
m_mapUsers.erase(it);
bRet =3D true;
}
}
=20
return bRet;
}
=20
My first thought was that the MAP container had issues when attempting =
to
"find" with 0 elements, but that didn't seem to affect anything. Any
thoughts?=20
=20
Are you sure that m_mapUsers is an object of type UserMap and UserMap is =
a
typedef of a map type?
=20
=20
=20
=20
=20
=20
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>=20
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net =
<http://www.noicys.cjb.net/>
=20
|