|
From: Shane B. <ast...@te...> - 2003-07-09 21:54:51
|
Hello,
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:
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_"
And here is the code in question.
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;
}
}
return bRet;
}
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?
-Shane |