2005-02-28 Clinton Ebadi <clinton@unknownlamer.org>
+ * source/Parser.C (parseLine): use map<>::find and an iterator to
+ find the IRC command instead of map<>::operator[] to avoid a
+ potential segfault
+
+ * source/Bot.C (waitForInput): Removed commented out code
+
* source/Socket.C (readLine): return String (buf.c_str ()) instead
of String (buf) so that only the buffer up to the first null is returned
(readLine): Added a comment explaining the usage of buf
if (serverConnection->handleInput())
nextServer();
-// std::list<DCCConnection *>::iterator it = dccConnections.begin();
-// std::list<DCCConnection *>::iterator it2;
-
-// while (it != dccConnections.end()) {
-// it2 = it;
-// ++it;
-// #ifdef _HPUX_SOURCE
-// if (rd & (*it2)->getFileDescriptor()) {
-// #else
-// if (FD_ISSET((*it2)->getFileDescriptor(), &rd)) {
-// #endif
-// if ((*it2)->handleInput()) {
-// delete *it2;
-// dccConnections.erase(it2);
-// }
-// }
-// }
-// }
dccConnections->checkInput (rd);
}
serverConnection->queue->sendJoin((*it).first, (*it).second->key);
}
-// std::list<DCCConnection *>::iterator it2;
-
-// for (std::list<DCCConnection *>::iterator it = dccConnections.begin();
-// it != dccConnections.end(); ) {
-// it2 = it;
-// ++it;
-// if ((*it2)->autoRemove && currentTime >= (std::time_t)((*it2)->lastSpoken + Bot::DCC_DELAY)) {
-// delete *it2;
-// dccConnections.erase(it2);
-// }
-// }
-
if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) {
serverConnection->queue->sendPing("Testing connection");
sentPing = true;
String command = st.next_token ();
String rest = st.rest ();
- if (fptr temp_func = functions[command])
- temp_func (cnx, from, rest);
+ // We must use map<>::find or else a new entry will be created in
+ // the map which will cause another lookup of the same invalid
+ // command to segfault the bot
+ std::map<std::string, fptr, std::less<std::string> >::const_iterator cit
+ = functions.find (command);
+
+ if (cit != functions.end ())
+ {
+ fptr temp_func = cit->second;
+ temp_func (cnx, from, rest);
+ }
+
delete from;
}