From cf8ea87372f220b09b01689b1729a88eb3b2a1d2 Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Tue, 31 May 2005 05:59:58 +0000 Subject: [PATCH] [project @ 2005-05-31 05:59:57 by unknown_lamer] Fixed all warnings and a few rarely triggered bugs --- ChangeLog | 30 ++++++++++++++++++++++ NEWS | 2 ++ TODO | 11 +++++--- source/Bot.C | 32 +++++++++++++---------- source/BotInterp.C | 2 +- source/BotInterp.H | 25 ++++++++++++++---- source/Commands.C | 55 ++++++++++++++++++++++++++++++---------- source/Socket.C | 2 +- source/String.C | 8 ++++-- source/StringTokenizer.C | 38 +++++++++++++++------------ source/StringTokenizer.H | 6 ++--- source/Utils.C | 8 +++--- 12 files changed, 156 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa9172a..3edeebc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2005-05-31 Clinton Ebadi + + * source/String.C (operator): Made index signed again, it's not + worth fixing this warning + + * source/Bot.C: Add casts to make this compile with unsigned int + as operator[] in String + + * source/String.C (operator): Made index unsigned + + * source/Utils.C: Made a few things unsigned to kill warnings + + * source/Socket.C (readLine): Made pos unsigned + + * source/Bot.C (Bot): Fixed initializer list order to kill warnings + + * source/BotInterp.C (RunTimers): Removed unused variable (Timer *t) + + * source/StringTokenizer.C (count_tokens): Changed return type to + unsigned int + (more_tokens_p): Made counter unsigned + + * source/StringTokenizer.H (class StringTokenizer): Made pos + std::string::size_type instead of int + + * source/Commands.C (TBan): Returns Ok is the ban is done instead + of falling off the end (oops) + + * source/BotInterp.H: Add general catch case (false) + 2005-03-11 Clinton Ebadi * configure.ac: Release 2.1.6 diff --git a/NEWS b/NEWS index f37c694..ce7be7a 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ IMPORTANT NOTES: ===================================================================== Version 2.1.7: +- Fixed a number of small bugs and corner cases +- Should compile without warnings (GCC 3.4) Version 2.1.6: - The String class has been removed and replaced by std::string diff --git a/TODO b/TODO index c85c714..08b342d 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,8 @@ Done: * Wrote config database class 2.2: +* Compile without warnings +* Finish Texinfo manual * Utils::valid_nickname_p should have a configurable max nick length (now that most networks allow for longer than nine character nicks). This is dependant upon the new configuration system @@ -12,15 +14,16 @@ Done: (e.g. bot:send-CTCP to send a CTCP message) * Add util functions for doing stuff like quoting CTCP messages * Finish adding hooks/send hooks -* Write Texinfo manual -* Use configuration database class -* Improve the help system * bot:protection/[none|no-ban|no-kick|no-deop] constants * bot:aop/[no|yes] constants -* Extend AOP to support +v (0 = no op, 1 = +o, 2 = +v) * Add DCC_CHAT_END hook for Scheme + +2.4: +* Use configuration database class +* Extend AOP to support +v (0 = no op, 1 = +o, 2 = +v) * Add !setcommandlevel (move ScriptCommands implementation to Commands and add a UserCommands) +* Improve the help system 2.4/3.0 (2.4 iff backwards compatibility is maintained, 3.0 otherwise): General: diff --git a/source/Bot.C b/source/Bot.C index cfcd972..c3a83a1 100644 --- a/source/Bot.C +++ b/source/Bot.C @@ -62,22 +62,28 @@ Bot::Bot(String filename, bool debug_on) userHost(""), localIP(""), commandChar(DEFAULT_COMMANDCHAR), - configFileName(filename), userListFileName(DEFAULT_USERLISTFILENAME), shitListFileName(DEFAULT_SHITLISTFILENAME), - logFileName(DEFAULT_LOGFILENAME), - logs_dir (DEFAULT_LOGDIR), helpFileName(DEFAULT_HELPFILENAME), initFileName(DEFAULT_INITFILENAME), + connected(false), + debug(debug_on), + stop(false), + sentPing(false), + startTime(time(NULL)), + currentTime(startTime), + lastNickNameChange(startTime), + lastChannelJoin(startTime), + serverConnection(0), + sentUserhostID(0), + receivedUserhostID(0), + logFileName(DEFAULT_LOGFILENAME), + logs_dir (DEFAULT_LOGDIR), + configFileName (filename), #ifdef USESCRIPTS scriptLogFileName(DEFAULT_SCRIPTLOGFILENAME), - autoexecFileName(DEFAULT_AUTOEXECFILENAME), + autoexecFileName(DEFAULT_AUTOEXECFILENAME) #endif - connected(false), - debug(debug_on), stop(false), sentPing(false), - startTime(time(NULL)), currentTime(startTime), - lastNickNameChange(startTime), lastChannelJoin(startTime), - serverConnection(0), sentUserhostID(0), receivedUserhostID(0) { #ifdef HAVE_STL_CLEAR wantedChannels.clear(); @@ -110,7 +116,7 @@ Bot::Bot(String filename, bool debug_on) line++; StringTokenizer st(temp); temp = Utils::trim_str (temp); - if (temp[0]=='#') continue; + if (temp[(unsigned int)0]=='#') continue; if (st.count_tokens (' ') != 2) { std::cerr << "Error when reading alias file (" << initFileName << ") line " << line << "...\n"; @@ -203,7 +209,7 @@ Bot::readConfig() file >> temp; - if (temp.length() == 0 || temp[0] == '#') { + if (temp.length() == 0 || temp[(unsigned int)0] == '#') { line++; continue; } @@ -219,7 +225,7 @@ Bot::readConfig() else if (command == "IRCNAME" || command == "REALNAME") ircName = parameters; else if (command == "CMDCHAR" || command == "COMMAND") - commandChar = parameters[0]; + commandChar = parameters[(unsigned int)0]; else if (command == "USERLIST") userListFileName = parameters; else if (command == "SHITLIST") @@ -247,7 +253,7 @@ Bot::readConfig() { if (parameters != logFileName) { - if (parameters[0] == '/') + if (parameters[(unsigned int)0] == '/') { set_log_dir ("/"); set_log_file (parameters.subString (1)); diff --git a/source/BotInterp.C b/source/BotInterp.C index 9abeb99..815c9bf 100644 --- a/source/BotInterp.C +++ b/source/BotInterp.C @@ -163,7 +163,7 @@ BotInterp::RunTimers(int now) std::list::iterator it = timersList.begin(); std::list::iterator it2 = timersList.end(); std::list::iterator it3; - Timer *t; + struct wrapper_data wd; wd.args = scm_listify (SCM_UNDEFINED); diff --git a/source/BotInterp.H b/source/BotInterp.H index ce0ecc7..a9c4dd3 100644 --- a/source/BotInterp.H +++ b/source/BotInterp.H @@ -48,15 +48,30 @@ struct Hook { bool operator< (const Hook &h) const { if (priority < h.priority) - return true; + { + return true; + } else if (priority > h.priority) - return false; + { + return false; + } else if (fallthru && h.fallthru) - return false; + { + return false; + } else if (fallthru && !h.fallthru) - return false; + { + return false; + } else if (!fallthru && h.fallthru) - return true; + { + return true; + } + else + { + // NOTE: This should never be reached + return false; + } } enum { diff --git a/source/Commands.C b/source/Commands.C index 44fc761..d007e33 100644 --- a/source/Commands.C +++ b/source/Commands.C @@ -676,45 +676,72 @@ Commands::TBan(Bot *bot, String channel, String who, int seconds) CHECK_CONNECTION; Channel *c = CHANNEL(channel); + String dest; + // Make sure all of the inputs are valid if (!c) - return NotOnChannel(channel); + { + return NotOnChannel(channel); + } if (!bot->iAmOp(channel)) - return NotChannelOp(channel); + { + return NotChannelOp(channel); + } if (seconds <= 0) - return InvalidTime(seconds); - - String dest; + { + return InvalidTime(seconds); + } + // Look for user if (!Utils::wildcard_p(who)) - dest = bot->getUserhost(channel, who); + { + dest = bot->getUserhost(channel, who); + } else - dest = who; + { + dest = who; + } if (dest.length() == 0) - return UserNotFound(who, channel); + { + return UserNotFound(who, channel); + } + dest = Utils::make_wildcard(dest); Mask m(dest); + // Make sure the user isn't protected from bans for (std::list::iterator it = bot->userList->l.begin(); it != bot->userList->l.end(); it++) - if (m.matches((*it)->mask) && - (*it)->channelMask.matches(channel) && - (*it)->prot >= User::NO_BAN) - return UserProtected(who, channel); + { + if (m.matches((*it)->mask) && + (*it)->channelMask.matches(channel) && + (*it)->prot >= User::NO_BAN) + { + return UserProtected(who, channel); + } + } + // Clear existing bans on the user for (std::vector::iterator it = c->channelBanlist.begin(); it != c->channelBanlist.end(); ++it) - if (m.matches((*it)->banMask)) - QUEUE->sendChannelMode(channel, "-b", (*it)->banMask.getMask()); + { + if (m.matches((*it)->banMask)) + { + QUEUE->sendChannelMode(channel, "-b", (*it)->banMask.getMask()); + } + } + // Ban them CHANNEL(channel)->addBan(dest, seconds); QUEUE->sendChannelMode(channel, "+b", dest); bot->todoList->addDeban(channel, dest, seconds); + + return Ok; } diff --git a/source/Socket.C b/source/Socket.C index 33a42d0..8c5fb9d 100644 --- a/source/Socket.C +++ b/source/Socket.C @@ -263,7 +263,7 @@ Socket::readLine() // that only the line that was just read is returned. static std::string buf (512, ' '); - int pos = 0; // pos in buffer + std::string::size_type pos = 0; // pos in buffer int nb; // number of bytes read by ::read char r; // temp var for storing output of read into std::string::size_type length = buf.length (); diff --git a/source/String.C b/source/String.C index 30665e1..8d6e5eb 100644 --- a/source/String.C +++ b/source/String.C @@ -171,8 +171,10 @@ String::indexOf (char c) } char & -String::operator[] (int i) +String::operator[] (int i_) { + unsigned int i = i_; + if (i < 0 || my_string.length () < i) { std::cerr << "String index out of range\n"; std::exit(1); @@ -181,8 +183,10 @@ String::operator[] (int i) } const char & -String::operator[](int i) const +String::operator[](int i_) const { + unsigned int i = i_; + if (i < 0 || my_string.length () < i) { std::cerr << "String index out of range\n"; exit(1); diff --git a/source/StringTokenizer.C b/source/StringTokenizer.C index 5455853..00f78e4 100644 --- a/source/StringTokenizer.C +++ b/source/StringTokenizer.C @@ -30,7 +30,7 @@ StringTokenizer::more_tokens_p () if (pos == st.length()) return false; - for (int i = pos; i < st.length(); i++) + for (std::string::size_type i = pos; i < st.length(); i++) if (st[i] != ' ' && st[i] != '\t') return true; @@ -43,17 +43,17 @@ StringTokenizer::more_tokens_p (char c) if (pos == st.length()) return false; - for (int i = pos; i < st.length(); i++) + for (std::string::size_type i = pos; i < st.length(); i++) if (st[i] != c) return true; return false; } -int +unsigned int StringTokenizer::count_tokens () { - int i = 0; + unsigned int i = 0; StringTokenizer s (st); while (s.more_tokens_p ()) @@ -65,10 +65,10 @@ StringTokenizer::count_tokens () return i; } -int +unsigned int StringTokenizer::count_tokens (char c) { - int i = 0; + unsigned int i = 0; StringTokenizer s(st); while (s.more_tokens_p (c)) @@ -83,12 +83,12 @@ StringTokenizer::count_tokens (char c) std::string StringTokenizer::next_token() { - int i = pos; + std::string::size_type i = pos; while (i < st.length() && (st[i] == ' ' || st[i] == '\t')) i++; - for (int j = i; j < st.length(); j++) + for (std::string::size_type j = i; j < st.length(); j++) if (st[j] == ' ' || st[j] == '\t') { pos = j + 1; @@ -102,16 +102,22 @@ StringTokenizer::next_token() std::string StringTokenizer::next_token (char c, bool empty) { - int i = pos; + std::string::size_type i = pos; + std::string::size_type j = 0; while (i < st.length() && (st[i] == c)) - i++; - for (int j = i; j < st.length(); j++) - if (st[j] == c) - { - pos = j + 1; - return st.substr (i, j - i); - } + { + i++; + } + + for (j = i; j < st.length(); j++) + { + if (st[j] == c) + { + pos = j + 1; + return st.substr (i, j - i); + } + } if (empty) return ""; diff --git a/source/StringTokenizer.H b/source/StringTokenizer.H index a950e20..56a9130 100644 --- a/source/StringTokenizer.H +++ b/source/StringTokenizer.H @@ -24,7 +24,7 @@ class StringTokenizer { std::string st; - int pos; + std::string::size_type pos; public: StringTokenizer(std::string); StringTokenizer(StringTokenizer &); @@ -32,8 +32,8 @@ public: bool more_tokens_p (); bool more_tokens_p (char); - int count_tokens(); - int count_tokens(char); + unsigned int count_tokens(); + unsigned int count_tokens(char); std::string next_token(); std::string next_token(char, bool = false); diff --git a/source/Utils.C b/source/Utils.C index afbb423..aca8663 100644 --- a/source/Utils.C +++ b/source/Utils.C @@ -52,7 +52,7 @@ Utils::get_key() bool Utils::IP_p (std::string host) { - for (int i = 0; i < host.length(); i++) + for (std::string::size_type i = 0; i < host.length(); i++) if (!std::isdigit (host[i]) && host[i] !='.') return false; return true; @@ -129,7 +129,7 @@ Utils::valid_nickname_p (std::string n) if (n[0] == '-' || std::isdigit(n[0]) || n.length() > 9) return false; - for (int i = 0; i < n.length(); i++) + for (std::string::size_type i = 0; i < n.length(); i++) if (!isvalid(n[i]) || std::isspace (n[i])) return false; @@ -217,9 +217,9 @@ Utils::str2time(std::string str) if (!std::isdigit (str[0])) return 0; - num.reserve (512); // reverse a buffer to speed things up + num.reserve (64); // reserve a buffer to speed things up - for (int i = 0; i < str.length(); i++) + for (std::string::size_type i = 0; i < str.length(); i++) { switch (str[i]) { -- 2.20.1