From 36040be2952186d56a6646ee7d972aaafdd4e31a Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 17 Nov 2017 00:02:03 +0000 Subject: [PATCH] Fix a ton of -Wsign-conversion warnings. --- include/channels.h | 2 +- include/configreader.h | 4 ++-- include/convto.h | 4 ++-- include/ctables.h | 8 ++++---- include/inspircd.h | 2 +- include/inspsocket.h | 13 +++++++++---- include/membership.h | 4 ++-- include/socket.h | 4 ++-- include/timer.h | 2 +- include/users.h | 4 ++-- src/channels.cpp | 2 +- src/command_parse.cpp | 2 +- src/configreader.cpp | 18 +++++++++--------- src/coremods/core_info/cmd_modules.cpp | 2 +- src/coremods/core_list.cpp | 8 ++++---- src/coremods/core_oper/cmd_kill.cpp | 2 +- src/coremods/core_oper/core_oper.h | 2 +- src/coremods/core_who.cpp | 4 ++-- src/coremods/core_whois.cpp | 11 ++++++----- src/helperfuncs.cpp | 4 ++-- src/inspircd.cpp | 2 +- src/inspsocket.cpp | 6 +++--- src/modules/m_alias.cpp | 2 +- src/modules/m_banredirect.cpp | 2 +- src/modules/m_callerid.cpp | 2 +- src/modules/m_chanhistory.cpp | 4 ++-- src/modules/m_cloaking.cpp | 8 ++++---- src/modules/m_clones.cpp | 2 +- src/modules/m_connectban.cpp | 2 +- src/modules/m_dccallow.cpp | 13 ++++++++++--- src/modules/m_dnsbl.cpp | 4 ++-- src/modules/m_httpd.cpp | 8 ++++---- src/modules/m_httpd_acl.cpp | 4 ++-- src/modules/m_ircv3_sts.cpp | 2 +- src/modules/m_messageflood.cpp | 5 ++++- src/modules/m_override.cpp | 2 +- src/modules/m_redirect.cpp | 2 +- src/modules/m_spanningtree/link.h | 2 +- src/modules/m_spanningtree/main.cpp | 8 ++++---- src/modules/m_spanningtree/server.cpp | 2 +- src/modules/m_spanningtree/treesocket1.cpp | 4 ++-- src/modules/m_spanningtree/utils.cpp | 4 ++-- src/modules/m_spanningtree/utils.h | 6 +++--- src/modules/m_timedbans.cpp | 2 +- src/modules/m_userip.cpp | 2 +- src/socket.cpp | 8 ++++---- src/timer.cpp | 2 +- src/users.cpp | 4 ++-- 48 files changed, 116 insertions(+), 100 deletions(-) diff --git a/include/channels.h b/include/channels.h index be872b7fe..365cdeabd 100644 --- a/include/channels.h +++ b/include/channels.h @@ -149,7 +149,7 @@ class CoreExport Channel : public Extensible * * @return The number of users on this channel */ - long GetUserCounter() const { return userlist.size(); } + size_t GetUserCounter() const { return userlist.size(); } /** Add a user pointer to the internal reference list * @param user The user to add diff --git a/include/configreader.h b/include/configreader.h index fc8c99d62..69c98a55e 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -285,12 +285,12 @@ class CoreExport ServerConfig /** Clones CIDR range for ipv4 (0-32) * Defaults to 32 (checks clones on all IPs seperately) */ - int c_ipv4_range; + unsigned char c_ipv4_range; /** Clones CIDR range for ipv6 (0-128) * Defaults to 128 (checks on all IPs seperately) */ - int c_ipv6_range; + unsigned char c_ipv6_range; /** Holds the server name of the local server * as defined by the administrator. diff --git a/include/convto.h b/include/convto.h index eaf14f6dc..c306283fc 100644 --- a/include/convto.h +++ b/include/convto.h @@ -100,9 +100,9 @@ template inline long ConvToInt(const T& in) return atol(tmp.str().c_str()); } -inline uint64_t ConvToUInt64(const std::string& in) +template inline TOut ConvToNum(const std::string& in) { - uint64_t ret; + TOut ret; std::istringstream tmp(in); if (!(tmp >> ret)) return 0; diff --git a/include/ctables.h b/include/ctables.h index 9376dbbcc..bba395919 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -112,7 +112,7 @@ class CoreExport CommandBase : public ServiceProvider public: /** User flags needed to execute the command or 0 */ - char flags_needed; + unsigned char flags_needed; /** Minimum number of parameters command takes */ @@ -157,7 +157,7 @@ class CoreExport CommandBase : public ServiceProvider /** How many seconds worth of penalty does this command have? */ - int Penalty; + unsigned int Penalty; /** Create a new command. * @param me The module which created this command. @@ -175,7 +175,7 @@ class CoreExport CommandBase : public ServiceProvider * @param parameter The parameter to encode. Can be modified in place. * @param index The parameter index (0 == first parameter). */ - virtual void EncodeParameter(std::string& parameter, int index); + virtual void EncodeParameter(std::string& parameter, unsigned int index); /** Disable or enable this command. * @param setting True to disable the command. @@ -234,7 +234,7 @@ class CoreExport Command : public CommandBase class CoreExport SplitCommand : public Command { public: - SplitCommand(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) + SplitCommand(Module* me, const std::string &cmd, unsigned int minpara = 0, unsigned int maxpara = 0) : Command(me, cmd, minpara, maxpara) {} virtual CmdResult Handle(const std::vector& parameters, User* user); virtual CmdResult HandleLocal(const std::vector& parameters, LocalUser* user); diff --git a/include/inspircd.h b/include/inspircd.h index 839cccb6a..5f5493350 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -339,7 +339,7 @@ class CoreExport InspIRCd * @param printable if false, the string will use characters 0-255; otherwise, * it will be limited to 0x30-0x7E ('0'-'~', nonspace printable characters) */ - std::string GenRandomStr(int length, bool printable = true); + std::string GenRandomStr(unsigned int length, bool printable = true); /** Generate a random integer. * This is generally more secure than rand() */ diff --git a/include/inspsocket.h b/include/inspsocket.h index 5c9c1059a..258d186b9 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -89,7 +89,12 @@ class CoreExport SocketTimeout : public Timer * @param thesock BufferedSocket to attach to * @param secs_from_now Seconds from now to time out */ - SocketTimeout(int fd, BufferedSocket* thesock, long secs_from_now) : Timer(secs_from_now), sock(thesock), sfd(fd) { } + SocketTimeout(int fd, BufferedSocket* thesock, unsigned int secs_from_now) + : Timer(secs_from_now) + , sock(thesock) + , sfd(fd) + { + } /** Handle tick event */ @@ -361,7 +366,7 @@ class CoreExport BufferedSocket : public StreamSocket * @param maxtime Time to wait for connection * @param connectbindip Address to bind to (if NULL, no bind will be done) */ - void DoConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip); + void DoConnect(const std::string& ipaddr, int aport, unsigned int maxtime, const std::string& connectbindip); /** This method is called when an outbound connection on your socket is * completed. @@ -387,8 +392,8 @@ class CoreExport BufferedSocket : public StreamSocket virtual ~BufferedSocket(); protected: void OnEventHandlerWrite() CXX11_OVERRIDE; - BufferedSocketError BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned long timeout); - BufferedSocketError BeginConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip); + BufferedSocketError BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned int timeout); + BufferedSocketError BeginConnect(const std::string& ipaddr, int aport, unsigned int maxtime, const std::string& connectbindip); }; inline IOHook* StreamSocket::GetIOHook() const { return iohook; } diff --git a/include/membership.h b/include/membership.h index c952d09ae..8630bb673 100644 --- a/include/membership.h +++ b/include/membership.h @@ -20,7 +20,7 @@ #pragma once -uint64_t ConvToUInt64(const std::string& in); +#include "convto.h" /** * Represents a member of a channel. @@ -60,7 +60,7 @@ class CoreExport Membership : public Extensible, public insp::intrusive_list_nod */ static Id IdFromString(const std::string& str) { - return ConvToUInt64(str); + return ConvToNum(str); } /** Constructor, sets the user and chan fields to the parameters, does NOT update any bookkeeping diff --git a/include/socket.h b/include/socket.h index 8c7cc2e4e..aec06b526 100644 --- a/include/socket.h +++ b/include/socket.h @@ -60,7 +60,7 @@ namespace irc struct sockaddr_in in4; struct sockaddr_in6 in6; /** Return the size of the structure for syscall passing */ - int sa_size() const; + socklen_t sa_size() const; /** Return port number or -1 if invalid */ int port() const; /** Return IP only */ @@ -84,7 +84,7 @@ namespace irc /** Construct a CIDR mask from the string. Will normalize (127.0.0.1/8 => 127.0.0.0/8). */ cidr_mask(const std::string& mask); /** Construct a CIDR mask of a given length from the given address */ - cidr_mask(const irc::sockets::sockaddrs& addr, int len); + cidr_mask(const irc::sockets::sockaddrs& addr, unsigned char len); /** Equality of bits, type, and length */ bool operator==(const cidr_mask& other) const; /** Ordering defined for maps */ diff --git a/include/timer.h b/include/timer.h index a597427e3..a116d456c 100644 --- a/include/timer.h +++ b/include/timer.h @@ -76,7 +76,7 @@ class CoreExport Timer /** Sets the interval between two ticks. */ - void SetInterval(time_t interval); + void SetInterval(unsigned int interval); /** Called when the timer ticks. * You should override this method with some useful code to diff --git a/include/users.h b/include/users.h index ef5964699..40c99517d 100644 --- a/include/users.h +++ b/include/users.h @@ -353,7 +353,7 @@ class CoreExport User : public Extensible unsigned int quitting:1; /** What type of user is this? */ - const unsigned int usertype:2; + const UserType usertype:2; /** Get client IP string from sockaddr, using static internal buffer * @return The IP string @@ -385,7 +385,7 @@ class CoreExport User : public Extensible /** Constructor * @throw CoreException if the UID allocated to the user already exists */ - User(const std::string& uid, Server* srv, int objtype); + User(const std::string& uid, Server* srv, UserType objtype); /** Returns the full displayed host of the user * This member function returns the hostname of the user as seen by other users diff --git a/src/channels.cpp b/src/channels.cpp index 1edc57693..1151fe0a5 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -267,7 +267,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (!limit.empty()) { FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str())))) + if (!MOD_RESULT.check(chan->GetUserCounter() < ConvToNum(limit))) { user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)"); return NULL; diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 3b3329261..61f59ac0b 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -359,7 +359,7 @@ CommandBase::~CommandBase() { } -void CommandBase::EncodeParameter(std::string& parameter, int index) +void CommandBase::EncodeParameter(std::string& parameter, unsigned int index) { } diff --git a/src/configreader.cpp b/src/configreader.cpp index 168bdd09b..18b62fb09 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -219,7 +219,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } } - int blk_count = config_data.count("connect"); + size_t blk_count = config_data.count("connect"); if (blk_count == 0) { // No connect blocks found; make a trivial default block @@ -231,14 +231,14 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } Classes.resize(blk_count); - std::map names; + std::map names; bool try_again = true; - for(int tries=0; try_again; tries++) + for(size_t tries = 0; try_again; tries++) { try_again = false; ConfigTagList tags = ConfTags("connect"); - int i=0; + size_t i = 0; for(ConfigIter it = tags.first; it != tags.second; ++it, ++i) { ConfigTag* tag = it->second; @@ -249,7 +249,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) std::string parentName = tag->getString("parent"); if (!parentName.empty()) { - std::map::iterator parentIter = names.find(parentName); + std::map::const_iterator parentIter = names.find(parentName); if (parentIter == names.end()) { try_again = true; @@ -311,7 +311,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) if (tag->readString("sendq", sendq)) { // attempt to guess a good hard/soft sendq from a single value - long value = atol(sendq.c_str()); + unsigned long value = strtoul(sendq.c_str(), NULL, 10); if (value > 16384) me->softsendqmax = value / 16; else @@ -444,8 +444,8 @@ void ServerConfig::Fill() PID = ConfValue("pid")->getString("file"); MaxChans = ConfValue("channels")->getInt("users", 20); OperMaxChans = ConfValue("channels")->getInt("opers"); - c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32); - c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone", 128); + c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32, 1, 32); + c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone", 128, 1, 128); Limits = ServerLimits(ConfValue("limits")); Paths = ServerPaths(ConfValue("path")); NoSnoticeStack = options->getBool("nosnoticestack", false); @@ -548,7 +548,7 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */ try { - for (int index = 0; index * sizeof(DeprecatedConfig) < sizeof(ChangedConfig); index++) + for (unsigned long index = 0; index * sizeof(DeprecatedConfig) < sizeof(ChangedConfig); index++) { std::string value; ConfigTagList tags = ConfTags(ChangedConfig[index].tag); diff --git a/src/coremods/core_info/cmd_modules.cpp b/src/coremods/core_info/cmd_modules.cpp index 47dd2dc92..fa8c2aebb 100644 --- a/src/coremods/core_info/cmd_modules.cpp +++ b/src/coremods/core_info/cmd_modules.cpp @@ -66,7 +66,7 @@ CmdResult CommandModules::Handle (const std::vector& parameters, Us if (IS_LOCAL(user) && user->HasPrivPermission("servers/auspex")) { std::string flags("VCO"); - int pos = 0; + size_t pos = 0; for (int mult = 2; mult <= VF_OPTCOMMON; mult *= 2, ++pos) if (!(V.Flags & mult)) flags[pos] = '-'; diff --git a/src/coremods/core_list.cpp b/src/coremods/core_list.cpp index 6a62d122f..3c29f7883 100644 --- a/src/coremods/core_list.cpp +++ b/src/coremods/core_list.cpp @@ -51,7 +51,7 @@ class CommandList : public Command */ CmdResult CommandList::Handle (const std::vector& parameters, User *user) { - int minusers = 0, maxusers = 0; + size_t minusers = 0, maxusers = 0; user->WriteNumeric(RPL_LISTSTART, "Channel", "Users Name"); @@ -59,11 +59,11 @@ CmdResult CommandList::Handle (const std::vector& parameters, User { if (parameters[0][0] == '<') { - maxusers = atoi((parameters[0].c_str())+1); + maxusers = strtoul((parameters[0].c_str() + 1), NULL, 10); } else if (parameters[0][0] == '>') { - minusers = atoi((parameters[0].c_str())+1); + minusers = strtoul((parameters[0].c_str() + 1), NULL, 10); } } @@ -76,7 +76,7 @@ CmdResult CommandList::Handle (const std::vector& parameters, User Channel* const chan = i->second; // attempt to match a glob pattern - long users = chan->GetUserCounter(); + size_t users = chan->GetUserCounter(); bool too_few = (minusers && (users <= minusers)); bool too_many = (maxusers && (users >= maxusers)); diff --git a/src/coremods/core_oper/cmd_kill.cpp b/src/coremods/core_oper/cmd_kill.cpp index 8a453f7f1..20bbe5a26 100644 --- a/src/coremods/core_oper/cmd_kill.cpp +++ b/src/coremods/core_oper/cmd_kill.cpp @@ -136,7 +136,7 @@ RouteDescriptor CommandKill::GetRouting(User* user, const std::vector uuid (see above), and also the reason (params[1]) // because we decorate it if the oper is local and want remote servers to see the diff --git a/src/coremods/core_oper/core_oper.h b/src/coremods/core_oper/core_oper.h index 338a369f5..619fdf1fa 100644 --- a/src/coremods/core_oper/core_oper.h +++ b/src/coremods/core_oper/core_oper.h @@ -74,7 +74,7 @@ class CommandKill : public Command CmdResult Handle(const std::vector& parameters, User* user); RouteDescriptor GetRouting(User* user, const std::vector& parameters); - void EncodeParameter(std::string& param, int index); + void EncodeParameter(std::string& param, unsigned int index); }; /** Handle /OPER. diff --git a/src/coremods/core_who.cpp b/src/coremods/core_who.cpp index 196bf0479..ba1883e77 100644 --- a/src/coremods/core_who.cpp +++ b/src/coremods/core_who.cpp @@ -146,10 +146,10 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) match = InspIRCd::Match(user->awaymsg, matchtext); else if (opt_time) { - long seconds = InspIRCd::Duration(matchtext); + time_t seconds = ServerInstance->Time() - InspIRCd::Duration(matchtext); // Okay, so time matching, we want all users connected `seconds' ago - if (user->signon >= ServerInstance->Time() - seconds) + if (user->signon >= seconds) match = true; } diff --git a/src/coremods/core_whois.cpp b/src/coremods/core_whois.cpp index c2fac7577..d726b6b6c 100644 --- a/src/coremods/core_whois.cpp +++ b/src/coremods/core_whois.cpp @@ -55,7 +55,7 @@ class CommandWhois : public SplitCommand Events::ModuleEventProvider evprov; Events::ModuleEventProvider lineevprov; - void DoWhois(LocalUser* user, User* dest, unsigned long signon, unsigned long idle); + void DoWhois(LocalUser* user, User* dest, time_t signon, unsigned long idle); void SendChanList(WhoisContextImpl& whois); public: @@ -173,7 +173,7 @@ void CommandWhois::SendChanList(WhoisContextImpl& whois) chanlist.Flush(whois); } -void CommandWhois::DoWhois(LocalUser* user, User* dest, unsigned long signon, unsigned long idle) +void CommandWhois::DoWhois(LocalUser* user, User* dest, time_t signon, unsigned long idle) { WhoisContextImpl whois(user, dest, lineevprov); @@ -247,7 +247,7 @@ CmdResult CommandWhois::HandleRemote(const std::vector& parameters, if (!localuser) return CMD_FAILURE; - unsigned long idle = ConvToInt(parameters.back()); + unsigned long idle = ConvToNum(parameters.back()); DoWhois(localuser, target, target->signon, idle); return CMD_SUCCESS; @@ -256,8 +256,9 @@ CmdResult CommandWhois::HandleRemote(const std::vector& parameters, CmdResult CommandWhois::HandleLocal(const std::vector& parameters, LocalUser* user) { User *dest; - int userindex = 0; - unsigned long idle = 0, signon = 0; + unsigned int userindex = 0; + unsigned long idle = 0; + time_t signon = 0; if (CommandParser::LoopCall(user, this, parameters, 0)) return CMD_SUCCESS; diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 7e992c4a6..ddcff5e55 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -393,13 +393,13 @@ std::string InspIRCd::TimeString(time_t curtime, const char* format, bool utc) return buffer; } -std::string InspIRCd::GenRandomStr(int length, bool printable) +std::string InspIRCd::GenRandomStr(unsigned int length, bool printable) { char* buf = new char[length]; GenRandom(buf, length); std::string rv; rv.resize(length); - for(int i=0; i < length; i++) + for(size_t i = 0; i < length; i++) rv[i] = printable ? 0x3F + (buf[i] & 0x3F) : buf[i]; delete[] buf; return rv; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 80d1df75d..6c45a1a0d 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -309,7 +309,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : /* Fall through to handle other weird values too */ std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl; std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--config ]" << std::endl << - std::string(static_cast(8+strlen(argv[0])), ' ') << "[--runasroot] [--version]" << std::endl; + std::string(static_cast(8+strlen(argv[0])), ' ') << "[--runasroot] [--version]" << std::endl; Exit(EXIT_STATUS_ARGV); break; } diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 9bfc6a73e..a564d3eec 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -48,7 +48,7 @@ BufferedSocket::BufferedSocket(int newfd) SocketEngine::AddFd(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); } -void BufferedSocket::DoConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip) +void BufferedSocket::DoConnect(const std::string& ipaddr, int aport, unsigned int maxtime, const std::string& connectbindip) { BufferedSocketError err = BeginConnect(ipaddr, aport, maxtime, connectbindip); if (err != I_ERR_NONE) @@ -59,7 +59,7 @@ void BufferedSocket::DoConnect(const std::string &ipaddr, int aport, unsigned lo } } -BufferedSocketError BufferedSocket::BeginConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip) +BufferedSocketError BufferedSocket::BeginConnect(const std::string& ipaddr, int aport, unsigned int maxtime, const std::string& connectbindip) { irc::sockets::sockaddrs addr, bind; if (!irc::sockets::aptosa(ipaddr, aport, addr)) @@ -80,7 +80,7 @@ BufferedSocketError BufferedSocket::BeginConnect(const std::string &ipaddr, int return BeginConnect(addr, bind, maxtime); } -BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned long timeout) +BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned int timeout) { if (fd < 0) fd = socket(dest.sa.sa_family, SOCK_STREAM, 0); diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index bdb242938..791186414 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -284,7 +284,7 @@ class ModuleAlias : public Module { if (isdigit(newline[i+1])) { - int len = ((i + 2 < newline.length()) && (newline[i+2] == '-')) ? 3 : 2; + size_t len = ((i + 2 < newline.length()) && (newline[i+2] == '-')) ? 3 : 2; std::string var = newline.substr(i, len); result.append(GetVar(var, original_line)); i += len - 1; diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 5202051f3..4c5d53d35 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -308,7 +308,7 @@ class ModuleBanRedirect : public Module if (destchan) destlimit = destchan->GetModeParameter(limitmode); - if(destchan && destchan->IsModeSet(redirectmode) && !destlimit.empty() && (destchan->GetUserCounter() >= atoi(destlimit.c_str()))) + if(destchan && destchan->IsModeSet(redirectmode) && !destlimit.empty() && (destchan->GetUserCounter() >= ConvToNum(destlimit))) { user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You are banned)"); return MOD_RES_DENY; diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 7b56ffce4..74334cd24 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -182,7 +182,7 @@ public: TRANSLATE1(TR_CUSTOM); } - void EncodeParameter(std::string& parameter, int index) + void EncodeParameter(std::string& parameter, unsigned int index) { // Send lists as-is (part of 2.0 compat) if (parameter.find(',') != std::string::npos) diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index a0929a0d0..a969ab2e2 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -70,8 +70,8 @@ class HistoryMode : public ParamMode > return MODEACTION_DENY; unsigned int len = ConvToInt(parameter.substr(0, colon)); - int time = InspIRCd::Duration(duration); - if (len == 0 || time < 0) + unsigned int time = InspIRCd::Duration(duration); + if (len == 0 || time == 0) return MODEACTION_DENY; if (len > maxlines && IS_LOCAL(source)) return MODEACTION_DENY; diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index f9a7fa380..1cfd9516c 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -187,7 +187,7 @@ class ModuleCloaking : public Module * @param id A unique ID for this type of item (to make it unique if the item matches) * @param len The length of the output. Maximum for MD5 is 16 characters. */ - std::string SegmentCloak(const std::string& item, char id, int len) + std::string SegmentCloak(const std::string& item, char id, size_t len) { std::string input; input.reserve(key.length() + 3 + item.length()); @@ -197,7 +197,7 @@ class ModuleCloaking : public Module input.append(item); std::string rv = Hash->GenerateRaw(input).substr(0,len); - for(int i=0; i < len; i++) + for(size_t i = 0; i < len; i++) { // this discards 3 bits per byte. We have an // overabundance of bits in the hash output, doesn't @@ -210,8 +210,8 @@ class ModuleCloaking : public Module std::string SegmentIP(const irc::sockets::sockaddrs& ip, bool full) { std::string bindata; - int hop1, hop2, hop3; - int len1, len2; + size_t hop1, hop2, hop3; + size_t len1, len2; std::string rv; if (ip.sa.sa_family == AF_INET6) { diff --git a/src/modules/m_clones.cpp b/src/modules/m_clones.cpp index b3e695bfd..3084b32a8 100644 --- a/src/modules/m_clones.cpp +++ b/src/modules/m_clones.cpp @@ -36,7 +36,7 @@ class CommandClones : public Command std::string clonesstr = "CLONES "; - unsigned long limit = atoi(parameters[0].c_str()); + unsigned long limit = strtoul(parameters[0].c_str(), NULL, 10); /* * Syntax of a /clones reply: diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index e0f9717c4..58b3bfeda 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -52,7 +52,7 @@ class ModuleConnectBan : public Module if (u->exempt) return; - int range = 32; + unsigned char range = 32; switch (u->client_sa.sa.sa_family) { diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index e687e1341..12955d709 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -61,11 +61,17 @@ class DCCAllow std::string nickname; std::string hostmask; time_t set_on; - long length; + unsigned long length; DCCAllow() { } - DCCAllow(const std::string &nick, const std::string &hm, const time_t so, const long ln) : nickname(nick), hostmask(hm), set_on(so), length(ln) { } + DCCAllow(const std::string& nick, const std::string& hm, time_t so, unsigned long ln) + : nickname(nick) + , hostmask(hm) + , set_on(so) + , length(ln) + { + } }; typedef std::vector userlist; @@ -412,7 +418,8 @@ class ModuleDCCAllow : public Module dccallowlist::iterator iter2 = dl->begin(); while (iter2 != dl->end()) { - if (iter2->length != 0 && (iter2->set_on + iter2->length) <= ServerInstance->Time()) + time_t expires = iter2->set_on + iter2->length; + if (iter2->length != 0 && expires <= ServerInstance->Time()) { u->WriteNumeric(997, u->nick, InspIRCd::Format("DCCALLOW entry for %s has expired", iter2->nickname.c_str())); iter2 = dl->erase(iter2); diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index b2b9c30ff..732717ff3 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -35,7 +35,7 @@ class DNSBLConfEntry : public refcountbase EnumBanaction banaction; EnumType type; long duration; - int bitmask; + unsigned int bitmask; unsigned char records[256]; unsigned long stats_hits, stats_misses; DNSBLConfEntry(): type(A_BITMASK),duration(86400),bitmask(0),stats_hits(0), stats_misses(0) {} @@ -279,7 +279,7 @@ class ModuleDNSBL : public Module if (tag->getString("type") == "bitmask") { e->type = DNSBLConfEntry::A_BITMASK; - e->bitmask = tag->getInt("bitmask"); + e->bitmask = tag->getInt("bitmask", 0, 0, UINT_MAX); } else { diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 05112eb9c..a20b85f9d 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -100,7 +100,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru AddToCull(); } - std::string Response(int response) + std::string Response(unsigned int response) { switch (response) { @@ -191,7 +191,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru } } - void SendHTTPError(int response) + void SendHTTPError(unsigned int response) { HTTPHeaders empty; std::string data = "Server error "+ConvToStr(response)+": "+Response(response)+"
"+ @@ -201,7 +201,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru WriteData(data); } - void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders) + void SendHeaders(unsigned long size, unsigned int response, HTTPHeaders &rheaders) { WriteData(http_version + " "+ConvToStr(response)+" "+Response(response)+"\r\n"); @@ -345,7 +345,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru } } - void Page(std::stringstream* n, int response, HTTPHeaders *hheaders) + void Page(std::stringstream* n, unsigned int response, HTTPHeaders *hheaders) { SendHeaders(n->str().length(), response, *hheaders); WriteData(n->str()); diff --git a/src/modules/m_httpd_acl.cpp b/src/modules/m_httpd_acl.cpp index 00a50d7a1..3f67fffca 100644 --- a/src/modules/m_httpd_acl.cpp +++ b/src/modules/m_httpd_acl.cpp @@ -93,9 +93,9 @@ class ModuleHTTPAccessList : public Module, public HTTPACLEventListener } } - void BlockAccess(HTTPRequest* http, int returnval, const std::string &extraheaderkey = "", const std::string &extraheaderval="") + void BlockAccess(HTTPRequest* http, unsigned int returnval, const std::string &extraheaderkey = "", const std::string &extraheaderval="") { - ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "BlockAccess (%d)", returnval); + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "BlockAccess (%u)", returnval); std::stringstream data("Access to this resource is denied by an access control list. Please contact your IRC administrator."); HTTPDocumentResponse response(this, *http, &data, returnval); diff --git a/src/modules/m_ircv3_sts.cpp b/src/modules/m_ircv3_sts.cpp index ee619903a..f3b936b41 100644 --- a/src/modules/m_ircv3_sts.cpp +++ b/src/modules/m_ircv3_sts.cpp @@ -163,7 +163,7 @@ class ModuleIRCv3STS : public Module if (host.empty()) throw ModuleException(" must contain a hostname, at " + tag->getTagLocation()); - int port = tag->getInt("port"); + unsigned int port = tag->getInt("port", 0, 0, UINT16_MAX); if (!HasValidSSLPort(port)) throw ModuleException(" must be a TLS port, at " + tag->getTagLocation()); diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index fa929294c..bf651bb65 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -37,7 +37,10 @@ class floodsettings time_t reset; insp::flat_map counters; - floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) + floodsettings(bool a, unsigned int b, unsigned int c) + : ban(a) + , secs(b) + , lines(c) { reset = ServerInstance->Time() + secs; } diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index 2094d3c96..cb36b3f51 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -189,7 +189,7 @@ class ModuleOverride : public Module if (chan->IsModeSet(key) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter(key)) return HandleJoinOverride(user, chan, keygiven, "the channel key", "+k"); - if (chan->IsModeSet(limit) && (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter(limit))) && (CanOverride(user,"LIMIT"))) + if (chan->IsModeSet(limit) && (chan->GetUserCounter() >= ConvToNum(chan->GetModeParameter(limit))) && (CanOverride(user,"LIMIT"))) return HandleJoinOverride(user, chan, keygiven, "the channel limit", "+l"); if (chan->IsBanned(user) && CanOverride(user,"BANWALK")) diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index b14de9ff9..77a4925fc 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -111,7 +111,7 @@ class ModuleRedirect : public Module { if (chan->IsModeSet(re) && chan->IsModeSet(limitmode)) { - if (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter(limitmode))) + if (chan->GetUserCounter() >= ConvToNum(chan->GetModeParameter(limitmode))) { const std::string& channel = *re.ext.get(chan); diff --git a/src/modules/m_spanningtree/link.h b/src/modules/m_spanningtree/link.h index 632982623..465e65ff8 100644 --- a/src/modules/m_spanningtree/link.h +++ b/src/modules/m_spanningtree/link.h @@ -33,7 +33,7 @@ class Link : public refcountbase std::vector AllowMasks; bool HiddenFromStats; std::string Hook; - int Timeout; + unsigned int Timeout; std::string Bind; bool Hidden; Link(ConfigTag* Tag) : tag(Tag) {} diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 2d76102bc..4acd15d62 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -273,12 +273,12 @@ void ModuleSpanningTree::AutoConnectServers(time_t curtime) void ModuleSpanningTree::DoConnectTimeout(time_t curtime) { - std::map >::iterator i = Utils->timeoutlist.begin(); + SpanningTreeUtilities::TimeoutList::iterator i = Utils->timeoutlist.begin(); while (i != Utils->timeoutlist.end()) { TreeSocket* s = i->first; - std::pair p = i->second; - std::map >::iterator me = i; + std::pair p = i->second; + SpanningTreeUtilities::TimeoutList::iterator me = i; i++; if (s->GetLinkState() == DYING) { @@ -287,7 +287,7 @@ void ModuleSpanningTree::DoConnectTimeout(time_t curtime) } else if (curtime > s->age + p.second) { - ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002 (timeout of %d seconds)",p.first.c_str(),p.second); + ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002 (timeout of %u seconds)",p.first.c_str(),p.second); Utils->timeoutlist.erase(me); s->Close(); } diff --git a/src/modules/m_spanningtree/server.cpp b/src/modules/m_spanningtree/server.cpp index 50f63e117..ecdad87f8 100644 --- a/src/modules/m_spanningtree/server.cpp +++ b/src/modules/m_spanningtree/server.cpp @@ -86,7 +86,7 @@ void CommandServer::HandleExtra(TreeServer* newserver, const std::vectorBeginBurst(ConvToUInt64(val)); + newserver->BeginBurst(ConvToNum(val)); } } diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index 370c38d2c..f9dccf7ce 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -46,7 +46,7 @@ TreeSocket::TreeSocket(Link* link, Autoconnect* myac, const std::string& ipaddr) capab->capab_phase = 0; DoConnect(ipaddr, link->Port, link->Timeout, link->Bind); - Utils->timeoutlist[this] = std::pair(linkID, link->Timeout); + Utils->timeoutlist[this] = std::pair(linkID, link->Timeout); SendCapabilities(1); } @@ -77,7 +77,7 @@ TreeSocket::TreeSocket(int newfd, ListenSocket* via, irc::sockets::sockaddrs* cl SendCapabilities(1); - Utils->timeoutlist[this] = std::pair(linkID, 30); + Utils->timeoutlist[this] = std::pair(linkID, 30); } void TreeSocket::CleanNegotiationInfo() diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 79dc24e6a..0a96ecfcd 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -118,7 +118,7 @@ CullResult SpanningTreeUtilities::cull() sock->Close(); } - for(std::map >::iterator i = timeoutlist.begin(); i != timeoutlist.end(); ++i) + for(TimeoutList::iterator i = timeoutlist.begin(); i != timeoutlist.end(); ++i) { TreeSocket* s = i->first; s->Close(); @@ -235,7 +235,7 @@ void SpanningTreeUtilities::ReadConfiguration() if (PingFreq == 0) PingFreq = 60; - if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1) + if (PingWarnTime > PingFreq - 1) PingWarnTime = 0; AutoconnectBlocks.clear(); diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index f262f9a48..3d34b93a6 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -48,7 +48,7 @@ class SpanningTreeUtilities : public classbase public: typedef std::set TreeSocketSet; - typedef std::map > TimeoutList; + typedef std::map > TimeoutList; /** Creator module */ @@ -75,7 +75,7 @@ class SpanningTreeUtilities : public classbase /* Number of seconds that a server can go without ping * before opers are warned of high latency. */ - int PingWarnTime; + unsigned int PingWarnTime; /** This variable represents the root of the server tree */ TreeServer *TreeRoot; @@ -100,7 +100,7 @@ class SpanningTreeUtilities : public classbase /** Ping frequency of server to server links */ - int PingFreq; + unsigned int PingFreq; /** Initialise utility class */ diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 8c1454d7e..1898ea88a 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -74,7 +74,7 @@ class CommandTban : public Command user->WriteNumeric(Numerics::NoSuchNick(parameters[0])); return CMD_FAILURE; } - int cm = channel->GetPrefixValue(user); + unsigned int cm = channel->GetPrefixValue(user); if (cm < HALFOP_VALUE) { user->WriteNumeric(ERR_CHANOPRIVSNEEDED, channel->name, "You do not have permission to set bans on this channel"); diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp index 6fa367bff..7853c35af 100644 --- a/src/modules/m_userip.cpp +++ b/src/modules/m_userip.cpp @@ -38,7 +38,7 @@ class CommandUserip : public Command bool checked_privs = false; bool has_privs = false; - for (int i = 0; i < (int)parameters.size(); i++) + for (size_t i = 0; i < parameters.size(); i++) { User *u = ServerInstance->FindNickOnly(parameters[i]); if ((u) && (u->registered == REG_ALL)) diff --git a/src/socket.cpp b/src/socket.cpp index 91c7cdeca..6133d9ee4 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -178,7 +178,7 @@ std::string irc::sockets::sockaddrs::str() const return ""; } -int irc::sockets::sockaddrs::sa_size() const +socklen_t irc::sockets::sockaddrs::sa_size() const { if (sa.sa_family == AF_INET) return sizeof(in4); @@ -198,7 +198,7 @@ bool irc::sockets::sockaddrs::operator==(const irc::sockets::sockaddrs& other) c return !memcmp(this, &other, sizeof(*this)); } -static void sa2cidr(irc::sockets::cidr_mask& cidr, const irc::sockets::sockaddrs& sa, int range) +static void sa2cidr(irc::sockets::cidr_mask& cidr, const irc::sockets::sockaddrs& sa, unsigned char range) { const unsigned char* base; unsigned char target_byte; @@ -239,7 +239,7 @@ static void sa2cidr(irc::sockets::cidr_mask& cidr, const irc::sockets::sockaddrs } } -irc::sockets::cidr_mask::cidr_mask(const irc::sockets::sockaddrs& sa, int range) +irc::sockets::cidr_mask::cidr_mask(const irc::sockets::sockaddrs& sa, unsigned char range) { sa2cidr(*this, sa, range); } @@ -267,7 +267,7 @@ std::string irc::sockets::cidr_mask::str() const irc::sockets::sockaddrs sa; sa.sa.sa_family = type; unsigned char* base; - int len; + size_t len; if (type == AF_INET) { base = (unsigned char*)&sa.in4.sin_addr; diff --git a/src/timer.cpp b/src/timer.cpp index 0b0d8bac3..48ad79df7 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -22,7 +22,7 @@ #include "inspircd.h" -void Timer::SetInterval(time_t newinterval) +void Timer::SetInterval(unsigned int newinterval) { ServerInstance->Timers.DelTimer(this); secs = newinterval; diff --git a/src/users.cpp b/src/users.cpp index f7cd00a07..c2ff9c5be 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -63,7 +63,7 @@ std::string User::GetModeLetters(bool includeparams) const return ret; } -User::User(const std::string& uid, Server* srv, int type) +User::User(const std::string& uid, Server* srv, UserType type) : age(ServerInstance->Time()) , signon(0) , uuid(uid) @@ -688,7 +688,7 @@ const std::string& User::GetRealHost() const irc::sockets::cidr_mask User::GetCIDRMask() { - int range = 0; + unsigned char range = 0; switch (client_sa.sa.sa_family) { case AF_INET6: -- 2.39.2