diff options
author | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-17 02:46:47 +0000 |
---|---|---|
committer | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-17 02:46:47 +0000 |
commit | 3712db9cc6365e556a803daf32416ae929e95330 (patch) | |
tree | 56d0b9739b925519608bf119867c73968d7b1cbe /src | |
parent | 0632c7946c9835f24049b8cf9130409206796b33 (diff) |
Invented safe delete-while-itering for hash_map.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6029 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/command_parse.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp index e56005751..3ce91afda 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -452,24 +452,34 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) bool CommandParser::RemoveCommands(const char* source) { - nspace::hash_map<std::string,command_t*>::iterator i, safeiter, last_iter; - last_iter = cmdlist.begin(); - + nspace::hash_map<std::string,command_t*>::iterator i,safei; for (i = cmdlist.begin(); i != cmdlist.end(); i++) { - if (i->second->source == std::string(source)) + safei = i; + safei++; + if (safei != cmdlist.end()) { - ServerInstance->Log(DEBUG, "removecommands(%s) Removing dependent command: %s", i->second->source.c_str(), i->second->command.c_str()); - safeiter = i; - i = last_iter; - cmdlist.erase(safeiter); - continue; + RemoveCommand(safei, source); } - last_iter = i; + } + safei = cmdlist.begin(); + if (safei != cmdlist.end()) + { + RemoveCommand(safei, source); } return true; } +void CommandParser::RemoveCommand(nspace::hash_map<std::string,command_t*>::iterator safei, const char* source) +{ + command_t* x = safei->second; + if (x->source == std::string(source)) + { + ServerInstance->Log(DEBUG,"removecommands(%s) Removing dependent command: %s",x->source.c_str(),x->command.c_str()); + cmdlist.erase(safei); + } +} + void CommandParser::ProcessBuffer(std::string &buffer,userrec *user) { std::string::size_type a; |