From 9203f40f41e4a735d379d13867d277c696fb28c5 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 Sep 2022 22:52:53 +0100 Subject: Fix some warnings noticed by the readability-* clang-tidy checkers. --- include/clientprotocol.h | 2 +- include/configparser.h | 2 +- include/configreader.h | 4 ++-- include/hashcomp.h | 2 +- include/inspircd.h | 6 +++--- include/mode.h | 4 ++-- include/usermanager.h | 2 +- include/users.h | 2 +- include/xline.h | 2 +- src/clientprotocol.cpp | 2 +- src/configparser.cpp | 2 +- src/configreader.cpp | 4 ++-- src/coremods/core_channel/core_channel.cpp | 3 ++- src/coremods/core_channel/extban.cpp | 6 ++++-- src/coremods/core_dns.cpp | 7 ++++--- src/coremods/core_info/cmd_admin.cpp | 2 +- src/coremods/core_info/cmd_motd.cpp | 2 +- src/coremods/core_info/cmd_time.cpp | 2 +- src/coremods/core_info/core_info.h | 2 +- src/coremods/core_list.cpp | 2 +- src/coremods/core_message.cpp | 4 ++-- src/coremods/core_mode.cpp | 4 ++-- src/coremods/core_oper/cmd_rehash.cpp | 3 +-- src/coremods/core_stats.cpp | 5 +++-- src/coremods/core_who.cpp | 2 +- src/coremods/core_xline/cmd_eline.cpp | 2 +- src/coremods/core_xline/cmd_gline.cpp | 2 +- src/coremods/core_xline/cmd_kline.cpp | 2 +- src/coremods/core_xline/cmd_qline.cpp | 2 +- src/coremods/core_xline/cmd_zline.cpp | 2 +- src/hashcomp.cpp | 2 +- src/helperfuncs.cpp | 14 +++++++------- src/inspsocket.cpp | 2 +- src/mode.cpp | 4 ++-- src/modulemanager.cpp | 2 +- src/modules/extra/m_argon2.cpp | 6 +++--- src/modules/extra/m_log_syslog.cpp | 2 +- src/modules/extra/m_mysql.cpp | 6 +++--- src/modules/extra/m_pgsql.cpp | 8 ++++---- src/modules/extra/m_regex_posix.cpp | 6 +++--- src/modules/extra/m_regex_re2.cpp | 4 ++-- src/modules/extra/m_ssl_gnutls.cpp | 8 ++++---- src/modules/m_abbreviation.cpp | 3 ++- src/modules/m_alias.cpp | 7 ++++--- src/modules/m_anticaps.cpp | 8 ++++---- src/modules/m_auditorium.cpp | 5 +---- src/modules/m_autoop.cpp | 2 +- src/modules/m_banexception.cpp | 3 ++- src/modules/m_bcrypt.cpp | 2 +- src/modules/m_cban.cpp | 2 +- src/modules/m_check.cpp | 2 +- src/modules/m_cloaking.cpp | 9 ++++++--- src/modules/m_codepage.cpp | 4 ++-- src/modules/m_connectban.cpp | 2 +- src/modules/m_dccallow.cpp | 17 ++++++++-------- src/modules/m_disable.cpp | 4 ++-- src/modules/m_dnsbl.cpp | 9 ++++----- src/modules/m_filter.cpp | 16 +++++++-------- src/modules/m_globalload.cpp | 8 ++++---- src/modules/m_ident.cpp | 2 +- src/modules/m_ircv3_capnotify.cpp | 4 +--- src/modules/m_ircv3_sts.cpp | 2 +- src/modules/m_joinflood.cpp | 2 +- src/modules/m_log_sql.cpp | 1 - src/modules/m_md5.cpp | 4 ++-- src/modules/m_nickflood.cpp | 2 +- src/modules/m_override.cpp | 2 +- src/modules/m_pbkdf2.cpp | 8 +++----- src/modules/m_repeat.cpp | 2 +- src/modules/m_restrictmsg.cpp | 2 +- src/modules/m_rline.cpp | 4 ++-- src/modules/m_sasl.cpp | 4 ++-- src/modules/m_sha2.cpp | 4 ++-- src/modules/m_showwhois.cpp | 2 +- src/modules/m_shun.cpp | 4 ++-- src/modules/m_spanningtree/capab.cpp | 12 ++++++++---- src/modules/m_spanningtree/commands.h | 2 +- src/modules/m_spanningtree/compat.cpp | 1 - src/modules/m_spanningtree/main.h | 8 ++++---- src/modules/m_spanningtree/override_map.cpp | 2 +- src/modules/m_spanningtree/ping.cpp | 1 - src/modules/m_spanningtree/pong.cpp | 1 - src/modules/m_spanningtree/precommand.cpp | 2 +- src/modules/m_spanningtree/server.cpp | 2 +- src/modules/m_spanningtree/treesocket.h | 10 +++++----- src/modules/m_spanningtree/treesocket2.cpp | 2 +- src/modules/m_spanningtree/utils.cpp | 4 ++-- src/modules/m_spanningtree/utils.h | 12 ++++++------ src/modules/m_sslinfo.cpp | 2 +- src/modules/m_svshold.cpp | 6 ++---- src/server.cpp | 6 +++--- src/socketengines/epoll.cpp | 2 +- src/usermanager.cpp | 2 +- src/users.cpp | 2 +- src/xline.cpp | 30 +++++++++-------------------- 95 files changed, 201 insertions(+), 212 deletions(-) diff --git a/include/clientprotocol.h b/include/clientprotocol.h index 83b1aa907..b3e85fd8f 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -693,7 +693,7 @@ private: * @param tagmap Tag map that contains all possible tags. * @return Whitelist of tags to send to the user. */ - TagSelection MakeTagWhitelist(LocalUser* user, const TagMap& tagmap) const; + static TagSelection MakeTagWhitelist(LocalUser* user, const TagMap& tagmap); public: /** Constructor. diff --git a/include/configparser.h b/include/configparser.h index ca87ef0f7..a80dd1fb5 100644 --- a/include/configparser.h +++ b/include/configparser.h @@ -36,5 +36,5 @@ struct ParseStack final bool ParseFile(const std::string& name, int flags, const std::string& mandatory_tag = std::string(), bool isexec = false); void DoInclude(std::shared_ptr includeTag, int flags); void DoReadFile(const std::string& key, const std::string& file, int flags, bool exec); - FilePtr DoOpenFile(const std::string& name, bool isexec); + static FilePtr DoOpenFile(const std::string& name, bool isexec); }; diff --git a/include/configreader.h b/include/configreader.h index 998249292..ca1bba5d7 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -349,14 +349,14 @@ public: * @param def The value to return if the tag doesn't exist. * @returns Either a tag from the config or EmptyTag. */ - std::shared_ptr ConfValue(const std::string& tag, std::shared_ptr def = nullptr); + std::shared_ptr ConfValue(const std::string& tag, std::shared_ptr def = nullptr) const; /** Get a list of configuration tags by name. * @param tag The name of the tags to get. * @param def The value to return if the tag doesn't exist. * @returns Either a list of tags from the config or an empty TagList. */ - TagList ConfTags(const std::string& tag, std::optional def = std::nullopt); + TagList ConfTags(const std::string& tag, std::optional def = std::nullopt) const; /** An empty configuration tag. */ std::shared_ptr EmptyTag; diff --git a/include/hashcomp.h b/include/hashcomp.h index 217fb2697..8b8c8f482 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -150,7 +150,7 @@ namespace irc /** Fetch the entire remaining stream, without tokenizing * @return The remaining part of the stream */ - const std::string GetRemaining(); + std::string GetRemaining(); /** Returns true if the end of the stream has been reached * @return True if the end of the stream has been reached, otherwise false diff --git a/include/inspircd.h b/include/inspircd.h index 461a20678..8fc89e528 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -298,11 +298,11 @@ public: * @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(size_t length, bool printable = true); + std::string GenRandomStr(size_t length, bool printable = true) const; /** Generate a random integer. * This is generally more secure than rand() */ - unsigned long GenRandomInt(unsigned long max); + unsigned long GenRandomInt(unsigned long max) const; /** Fill a buffer with random bits */ std::function GenRandom; @@ -475,7 +475,7 @@ public: * @param hashtype The hash from the config file * @return True if the strings match, false if they do not */ - bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype); + static bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype); /** Attempt to write the process id to a given file */ diff --git a/include/mode.h b/include/mode.h index d7d4dd2e9..55ee5072d 100644 --- a/include/mode.h +++ b/include/mode.h @@ -785,14 +785,14 @@ public: * @param rank The rank to search for prefix modes near. * @return A pointer to the PrefixMode or NULL if a prefix mode wasn't found. */ - PrefixMode* FindNearestPrefixMode(ModeHandler::Rank rank); + PrefixMode* FindNearestPrefixMode(ModeHandler::Rank rank) const; /** Find a mode handler by its prefix. * If there is no mode handler with the given prefix, NULL will be returned. * @param pfxletter The prefix to find, e.g. '@' * @return The mode handler which handles this prefix, or NULL if there is none. */ - PrefixMode* FindPrefix(unsigned char pfxletter); + PrefixMode* FindPrefix(unsigned char pfxletter) const; /** Get a list of all mode handlers that inherit from ListModeBase * @return A list containing ListModeBase modes diff --git a/include/usermanager.h b/include/usermanager.h index be3dca18e..cec2b0e76 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -188,7 +188,7 @@ public: * @param text The text format string to send * @param ... The format arguments */ - void ServerNoticeAll(const char* text, ...) ATTR_PRINTF(2, 3); + void ServerNoticeAll(const char* text, ...) const ATTR_PRINTF(2, 3); /** Retrieves the next already sent id, guaranteed to be not equal to any user's already_sent field * @return Next already_sent id diff --git a/include/users.h b/include/users.h index ce8ffd662..c94317937 100644 --- a/include/users.h +++ b/include/users.h @@ -340,7 +340,7 @@ public: /** Get CIDR mask, using default range, for this user */ - irc::sockets::cidr_mask GetCIDRMask(); + irc::sockets::cidr_mask GetCIDRMask() const; /** Changes the remote socket address for this user. * @param sa The new socket address. diff --git a/include/xline.h b/include/xline.h index 0827adbd3..9e4864071 100644 --- a/include/xline.h +++ b/include/xline.h @@ -413,7 +413,7 @@ public: /** Split an ident and host into two separate strings. * This allows for faster matching. */ - IdentHostPair IdentSplit(const std::string &ident_and_host); + static IdentHostPair IdentSplit(const std::string &ident_and_host); /** Checks what users match E-lines and sets their ban exempt flag accordingly. */ diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index 91317640c..f3838e468 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -46,7 +46,7 @@ bool ClientProtocol::Serializer::HandleTag(LocalUser* user, const std::string& t return true; } -ClientProtocol::TagSelection ClientProtocol::Serializer::MakeTagWhitelist(LocalUser* user, const TagMap& tagmap) const +ClientProtocol::TagSelection ClientProtocol::Serializer::MakeTagWhitelist(LocalUser* user, const TagMap& tagmap) { TagSelection tagwl; for (TagMap::const_iterator i = tagmap.begin(); i != tagmap.end(); ++i) diff --git a/src/configparser.cpp b/src/configparser.cpp index 7dc603569..08cd88c7d 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -112,7 +112,7 @@ struct Parser final } } - bool wordchar(char ch) + static bool wordchar(char ch) { return isalnum(ch) || ch == '-' diff --git a/src/configreader.cpp b/src/configreader.cpp index 176a1d6c6..efe3af94d 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -554,7 +554,7 @@ void ServerConfig::ApplyModules(User* user) } } -std::shared_ptr ServerConfig::ConfValue(const std::string& tag, std::shared_ptr def) +std::shared_ptr ServerConfig::ConfValue(const std::string& tag, std::shared_ptr def) const { auto tags = insp::equal_range(config_data, tag); if (tags.empty()) @@ -568,7 +568,7 @@ std::shared_ptr ServerConfig::ConfValue(const std::string& tag, std:: return tags.begin()->second; } -ServerConfig::TagList ServerConfig::ConfTags(const std::string& tag, std::optional def) +ServerConfig::TagList ServerConfig::ConfTags(const std::string& tag, std::optional def) const { auto range = insp::equal_range(config_data, tag); return range.empty() && def ? *def : range; diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index f9e156d80..631b8d9d4 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -351,7 +351,8 @@ public: ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) override { bool inverted; - std::string name, value; + std::string name; + std::string value; if (!ExtBan::Parse(mask, name, value, inverted)) return MOD_RES_PASSTHRU; diff --git a/src/coremods/core_channel/extban.cpp b/src/coremods/core_channel/extban.cpp index f42e49b68..2e36cf6d9 100644 --- a/src/coremods/core_channel/extban.cpp +++ b/src/coremods/core_channel/extban.cpp @@ -29,7 +29,8 @@ void ExtBanManager::AddExtBan(ExtBan::Base* extban) bool ExtBanManager::Canonicalize(std::string& text) const { bool inverted; // Intentionally unused - std::string xbname, xbvalue; + std::string xbname; + std::string xbvalue; if (!ExtBan::Parse(text, xbname, xbvalue, inverted)) return false; // Not an extban. @@ -88,7 +89,8 @@ ModResult ExtBanManager::GetStatus(ExtBan::Acting* extban, User* user, Channel* for (const ListModeBase::ListItem& ban : *list) { bool inverted; - std::string xbname, xbvalue; + std::string xbname; + std::string xbvalue; if (!ExtBan::Parse(ban.mask, xbname, xbvalue, inverted)) continue; diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index d94199a8d..a3018ac75 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -71,7 +71,8 @@ private: std::string UnpackName(const unsigned char* input, unsigned short input_size, unsigned short& pos) { std::string name; - unsigned short pos_ptr = pos, lowest_ptr = input_size; + unsigned short pos_ptr = pos; + unsigned short lowest_ptr = input_size; bool compressed = false; if (pos_ptr >= input_size) @@ -89,7 +90,7 @@ private: throw Exception(creator, "Unable to unpack name - bogus compression header"); /* Place pos at the second byte of the first (farthest) compression pointer */ - if (compressed == false) + if (!compressed) { ++pos; compressed = true; @@ -112,7 +113,7 @@ private: name += input[pos_ptr + i]; pos_ptr += offset + 1; - if (compressed == false) + if (!compressed) /* Move up pos */ pos = pos_ptr; } diff --git a/src/coremods/core_info/cmd_admin.cpp b/src/coremods/core_info/cmd_admin.cpp index 955f83075..823384519 100644 --- a/src/coremods/core_info/cmd_admin.cpp +++ b/src/coremods/core_info/cmd_admin.cpp @@ -44,7 +44,7 @@ CommandAdmin::CommandAdmin(Module* parent) CmdResult CommandAdmin::Handle(User* user, const Params& parameters) { - if (parameters.size() > 0 && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) + if (!parameters.empty() && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) return CmdResult::SUCCESS; user->WriteRemoteNumeric(RPL_ADMINME, ServerInstance->Config->GetServerName(), "Administrative info"); diff --git a/src/coremods/core_info/cmd_motd.cpp b/src/coremods/core_info/cmd_motd.cpp index 7ce5419f1..25cf7bac7 100644 --- a/src/coremods/core_info/cmd_motd.cpp +++ b/src/coremods/core_info/cmd_motd.cpp @@ -42,7 +42,7 @@ CommandMotd::CommandMotd(Module* parent) CmdResult CommandMotd::Handle(User* user, const Params& parameters) { - if (parameters.size() > 0 && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) + if (!parameters.empty() && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) { // Give extra penalty if a non-oper queries the /MOTD of a remote server LocalUser* localuser = IS_LOCAL(user); diff --git a/src/coremods/core_info/cmd_time.cpp b/src/coremods/core_info/cmd_time.cpp index 9713d4ef9..e8fa6ec3d 100644 --- a/src/coremods/core_info/cmd_time.cpp +++ b/src/coremods/core_info/cmd_time.cpp @@ -40,7 +40,7 @@ CommandTime::CommandTime(Module* parent) CmdResult CommandTime::Handle(User* user, const Params& parameters) { - if (parameters.size() > 0 && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) + if (!parameters.empty() && !irc::equals(parameters[0], ServerInstance->Config->ServerName)) return CmdResult::SUCCESS; user->WriteRemoteNumeric(RPL_TIME, ServerInstance->Config->GetServerName(), InspIRCd::TimeString(ServerInstance->Time())); diff --git a/src/coremods/core_info/core_info.h b/src/coremods/core_info/core_info.h index 64c8df426..29cf7c8f5 100644 --- a/src/coremods/core_info/core_info.h +++ b/src/coremods/core_info/core_info.h @@ -42,7 +42,7 @@ private: * @param buffer The buffer to append to. * @param value An ISUPPORT token value. */ - void AppendValue(std::string& buffer, const std::string& value); + static void AppendValue(std::string& buffer, const std::string& value); /** Builds the ISUPPORT numerics from a list of tokens. * @param tokens The tokens to build from. diff --git a/src/coremods/core_list.cpp b/src/coremods/core_list.cpp index dd45d4343..6b30957f8 100644 --- a/src/coremods/core_list.cpp +++ b/src/coremods/core_list.cpp @@ -38,7 +38,7 @@ private: * @param value The parameter containing a minute count. * @return The UNIX time at \p value minutes ago. */ - time_t ParseMinutes(const std::string& value) + static time_t ParseMinutes(const std::string& value) { time_t minutes = ConvToNum(value.c_str() + 2); if (!minutes) diff --git a/src/coremods/core_message.cpp b/src/coremods/core_message.cpp index 89cb4bdd3..481f4e325 100644 --- a/src/coremods/core_message.cpp +++ b/src/coremods/core_message.cpp @@ -102,7 +102,7 @@ class CommandMessage final private: const MessageType msgtype; - bool FirePreEvents(User* source, MessageTarget& msgtarget, MessageDetails& msgdetails) + static bool FirePreEvents(User* source, MessageTarget& msgtarget, MessageDetails& msgdetails) { // Inform modules that a message wants to be sent. ModResult modres; @@ -126,7 +126,7 @@ private: return true; } - CmdResult FirePostEvent(User* source, const MessageTarget& msgtarget, const MessageDetails& msgdetails) + static CmdResult FirePostEvent(User* source, const MessageTarget& msgtarget, const MessageDetails& msgdetails) { // If the source is local and was not sending a CTCP reply then update their idle time. LocalUser* lsource = IS_LOCAL(source); diff --git a/src/coremods/core_mode.cpp b/src/coremods/core_mode.cpp index 6fc377707..e6fba59bd 100644 --- a/src/coremods/core_mode.cpp +++ b/src/coremods/core_mode.cpp @@ -294,7 +294,7 @@ class CoreModMode final private: CommandMode cmdmode; - std::string GenerateModeList(ModeType mt) + static std::string GenerateModeList(ModeType mt) { // Type A: Modes that add or remove an address to or from a list. These // modes MUST always have a parameter when sent from the server to a @@ -351,7 +351,7 @@ private: return InspIRCd::Format("%s,%s,%s,%s", type1.c_str(), type2.c_str(), type3.c_str(), type4.c_str()); } - std::string GeneratePrefixList(bool includemodechars) + static std::string GeneratePrefixList(bool includemodechars) { std::vector prefixes; for (const auto& pm : ServerInstance->Modes.GetPrefixModes()) diff --git a/src/coremods/core_oper/cmd_rehash.cpp b/src/coremods/core_oper/cmd_rehash.cpp index 7242d4b85..b3684f0c7 100644 --- a/src/coremods/core_oper/cmd_rehash.cpp +++ b/src/coremods/core_oper/cmd_rehash.cpp @@ -46,8 +46,7 @@ CommandRehash::CommandRehash(Module* parent) CmdResult CommandRehash::Handle(User* user, const Params& parameters) { - std::string param = parameters.size() ? parameters[0] : ""; - + std::string param = parameters.empty() ? "" : parameters[0]; FOREACH_MOD(OnPreRehash, (user, param)); if (param.empty()) diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index c43ccbd69..727fc1569 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -232,7 +232,9 @@ void CommandStats::DoStats(Stats::Context& stats) stats.AddRow(249, "Channels: "+ConvToStr(ServerInstance->Channels.GetChans().size())); stats.AddRow(249, "Commands: "+ConvToStr(ServerInstance->Parser.GetCommands().size())); - float kbitpersec_in, kbitpersec_out, kbitpersec_total; + float kbitpersec_in; + float kbitpersec_out; + float kbitpersec_total; SocketEngine::GetStats().GetBandwidth(kbitpersec_in, kbitpersec_out, kbitpersec_total); stats.AddRow(249, InspIRCd::Format("Bandwidth total: %03.5f kilobits/sec", kbitpersec_total)); @@ -372,7 +374,6 @@ void CommandStats::DoStats(Stats::Context& stats) stats.AddRow(219, statschar, "End of /STATS report"); ServerInstance->SNO.WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)", (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); - return; } CmdResult CommandStats::Handle(User* user, const Params& parameters) diff --git a/src/coremods/core_who.cpp b/src/coremods/core_who.cpp index 0386abca8..f211b522d 100644 --- a/src/coremods/core_who.cpp +++ b/src/coremods/core_who.cpp @@ -176,7 +176,7 @@ private: } /** Determines whether WHO flags match a specific channel user. */ - bool MatchChannel(LocalUser* source, Membership* memb, WhoData& data); + static bool MatchChannel(LocalUser* source, Membership* memb, WhoData& data); /** Determines whether WHO flags match a specific user. */ bool MatchUser(LocalUser* source, User* target, WhoData& data); diff --git a/src/coremods/core_xline/cmd_eline.cpp b/src/coremods/core_xline/cmd_eline.cpp index b285d687a..41a5031e8 100644 --- a/src/coremods/core_xline/cmd_eline.cpp +++ b/src/coremods/core_xline/cmd_eline.cpp @@ -69,7 +69,7 @@ CmdResult CommandEline::Handle(User* user, const Params& parameters) user->WriteNotice("*** Invalid duration for E-line."); return CmdResult::FAILURE; } - ELine* el = new ELine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str()); + ELine* el = new ELine(ServerInstance->Time(), duration, user->nick, parameters[2], ih.first, ih.second); if (ServerInstance->XLines->AddLine(el, user)) { if (!duration) diff --git a/src/coremods/core_xline/cmd_gline.cpp b/src/coremods/core_xline/cmd_gline.cpp index b9da576c2..634f3efa6 100644 --- a/src/coremods/core_xline/cmd_gline.cpp +++ b/src/coremods/core_xline/cmd_gline.cpp @@ -76,7 +76,7 @@ CmdResult CommandGline::Handle(User* user, const Params& parameters) user->WriteNotice("*** Invalid duration for G-line."); return CmdResult::FAILURE; } - GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str()); + GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick, parameters[2], ih.first, ih.second); if (ServerInstance->XLines->AddLine(gl, user)) { if (!duration) diff --git a/src/coremods/core_xline/cmd_kline.cpp b/src/coremods/core_xline/cmd_kline.cpp index 70ba6e020..b130fe567 100644 --- a/src/coremods/core_xline/cmd_kline.cpp +++ b/src/coremods/core_xline/cmd_kline.cpp @@ -76,7 +76,7 @@ CmdResult CommandKline::Handle(User* user, const Params& parameters) user->WriteNotice("*** Invalid duration for K-line."); return CmdResult::FAILURE; } - KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str()); + KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick, parameters[2], ih.first, ih.second); if (ServerInstance->XLines->AddLine(kl,user)) { if (!duration) diff --git a/src/coremods/core_xline/cmd_qline.cpp b/src/coremods/core_xline/cmd_qline.cpp index c0eef5def..7d79f32e7 100644 --- a/src/coremods/core_xline/cmd_qline.cpp +++ b/src/coremods/core_xline/cmd_qline.cpp @@ -58,7 +58,7 @@ CmdResult CommandQline::Handle(User* user, const Params& parameters) user->WriteNotice("*** Invalid duration for Q-line."); return CmdResult::FAILURE; } - QLine* ql = new QLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str()); + QLine* ql = new QLine(ServerInstance->Time(), duration, user->nick, parameters[2], parameters[0]); if (ServerInstance->XLines->AddLine(ql,user)) { if (!duration) diff --git a/src/coremods/core_xline/cmd_zline.cpp b/src/coremods/core_xline/cmd_zline.cpp index c400f098b..8eb07c4be 100644 --- a/src/coremods/core_xline/cmd_zline.cpp +++ b/src/coremods/core_xline/cmd_zline.cpp @@ -76,7 +76,7 @@ CmdResult CommandZline::Handle(User* user, const Params& parameters) user->WriteNotice("*** Invalid duration for Z-line."); return CmdResult::FAILURE; } - ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr); + ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick, parameters[2], ipaddr); if (ServerInstance->XLines->AddLine(zl,user)) { if (!duration) diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 2f18d14d4..03ba05103 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -253,7 +253,7 @@ bool irc::sepstream::GetToken(std::string &token) return true; } -const std::string irc::sepstream::GetRemaining() +std::string irc::sepstream::GetRemaining() { return !this->StreamEnd() ? this->tokens.substr(this->pos) : ""; } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index ac2293722..236f2e9de 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -130,7 +130,7 @@ void InspIRCd::ProcessColors(std::vector& input) for (auto& ret : input) { - for(int i = 0; special[i].character.empty() == false; ++i) + for(int i = 0; !special[i].character.empty(); ++i) { std::string::size_type pos = ret.find(special[i].character); if(pos == std::string::npos) // Couldn't find the character, skip this line @@ -400,7 +400,7 @@ std::string InspIRCd::Format(va_list& vaList, const char* formatString) va_list dst; va_copy(dst, vaList); - int vsnret = vsnprintf(&formatBuffer[0], formatBuffer.size(), formatString, dst); + int vsnret = vsnprintf(formatBuffer.data(), formatBuffer.size(), formatString, dst); va_end(dst); if (vsnret > 0 && static_cast(vsnret) < formatBuffer.size()) @@ -411,7 +411,7 @@ std::string InspIRCd::Format(va_list& vaList, const char* formatString) formatBuffer.resize(formatBuffer.size() * 2); } - return std::string(&formatBuffer[0]); + return std::string(formatBuffer.data()); } std::string InspIRCd::Format(const char* formatString, ...) @@ -453,19 +453,19 @@ std::string InspIRCd::TimeString(time_t curtime, const char* format, bool utc) return buffer; } -std::string InspIRCd::GenRandomStr(size_t length, bool printable) +std::string InspIRCd::GenRandomStr(size_t length, bool printable) const { std::vector str(length); - GenRandom(&str[0], length); + GenRandom(str.data(), length); if (printable) for (size_t i = 0; i < length; i++) str[i] = 0x3F + (str[i] & 0x3F); - return std::string(&str[0], str.size()); + return std::string(str.data(), str.size()); } // NOTE: this has a slight bias for lower values if max is not a power of 2. // Don't use it if that matters. -unsigned long InspIRCd::GenRandomInt(unsigned long max) +unsigned long InspIRCd::GenRandomInt(unsigned long max) const { unsigned long rv; GenRandom(reinterpret_cast(&rv), sizeof(rv)); diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 71fb493ec..acf2816e2 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -403,7 +403,7 @@ bool SocketTimeout::Tick() } void BufferedSocket::OnConnected() { } -void BufferedSocket::OnTimeout() { return; } +void BufferedSocket::OnTimeout() { } void BufferedSocket::OnEventHandlerWrite() { diff --git a/src/mode.cpp b/src/mode.cpp index 2b8e70f42..5eca116cb 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -711,7 +711,7 @@ PrefixMode* ModeParser::FindPrefixMode(unsigned char modeletter) } -PrefixMode* ModeParser::FindNearestPrefixMode(ModeHandler::Rank rank) +PrefixMode* ModeParser::FindNearestPrefixMode(ModeHandler::Rank rank) const { PrefixMode* pm = nullptr; for (const auto& thispm : GetPrefixModes()) @@ -727,7 +727,7 @@ PrefixMode* ModeParser::FindNearestPrefixMode(ModeHandler::Rank rank) return pm; } -PrefixMode* ModeParser::FindPrefix(unsigned char pfxletter) +PrefixMode* ModeParser::FindPrefix(unsigned char pfxletter) const { for (const auto& pm : GetPrefixModes()) { diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 67b5ec2a5..fe5e806af 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -60,7 +60,7 @@ bool ModuleManager::Load(const std::string& modname, bool defer) } Module* newmod = nullptr; - DLLManager* newhandle = new DLLManager(moduleFile.c_str()); + DLLManager* newhandle = new DLLManager(moduleFile); ServiceList newservices; if (!defer) this->NewServices = &newservices; diff --git a/src/modules/extra/m_argon2.cpp b/src/modules/extra/m_argon2.cpp index 57e2d895d..e972939fe 100644 --- a/src/modules/extra/m_argon2.cpp +++ b/src/modules/extra/m_argon2.cpp @@ -137,9 +137,9 @@ public: data.length(), salt.c_str(), salt.length(), - &raw_data[0], + raw_data.data(), raw_data.size(), - &encoded_data[0], + encoded_data.data(), encoded_data.size(), argon2Type, config.version); @@ -152,7 +152,7 @@ public: // to do anything useful with them if we don't encode them. // So we pretend this is the raw version, and instead make // ToPrintable return its input. - return std::string(&encoded_data[0], encoded_data.size()); + return std::string(encoded_data.data(), encoded_data.size()); } std::string ToPrintable(const std::string& raw) override diff --git a/src/modules/extra/m_log_syslog.cpp b/src/modules/extra/m_log_syslog.cpp index a3cf23ec6..62d08e45e 100644 --- a/src/modules/extra/m_log_syslog.cpp +++ b/src/modules/extra/m_log_syslog.cpp @@ -26,7 +26,7 @@ class SyslogMethod final { private: // Converts an InspIRCd log level to syslog priority. - int LevelToPriority(Log::Level level) + static int LevelToPriority(Log::Level level) { switch (level) { diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index c76034cc1..51fdef06c 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -269,7 +269,7 @@ class SQLConnection final : public SQL::Provider { private: - bool EscapeString(SQL::Query* query, const std::string& in, std::string& out) + bool EscapeString(SQL::Query* query, const std::string& in, std::string& out) const { // In the worst case each character may need to be encoded as using two bytes and one // byte is the NUL terminator. @@ -281,7 +281,7 @@ private: // Unfortunately, someone genius decided that mysql_escape_string should return an // unsigned type even though -1 is returned on error so checking whether an error // happened is a bit cursed. - unsigned long escapedsize = mysql_escape_string(&buffer[0], in.c_str(), in.length()); + unsigned long escapedsize = mysql_escape_string(buffer.data(), in.c_str(), in.length()); if (escapedsize == static_cast(-1)) { SQL::Error err(SQL::QSEND_FAIL, InspIRCd::Format("%u: %s", mysql_errno(connection), mysql_error(connection))); @@ -289,7 +289,7 @@ private: return false; } - out.append(&buffer[0], escapedsize); + out.append(buffer.data(), escapedsize); return true; } diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index ad3743ad9..e388f377f 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -446,10 +446,10 @@ restart: std::string parm = p[param++]; std::vector buffer(parm.length() * 2 + 1); int error; - size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error); + size_t escapedsize = PQescapeStringConn(sql, buffer.data(), parm.data(), parm.length(), &error); if (error) ServerInstance->Logs.Debug(MODNAME, "BUG: Apparently PQescapeStringConn() failed"); - res.append(&buffer[0], escapedsize); + res.append(buffer.data(), escapedsize); } } } @@ -477,10 +477,10 @@ restart: std::string parm = it->second; std::vector buffer(parm.length() * 2 + 1); int error; - size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error); + size_t escapedsize = PQescapeStringConn(sql, buffer.data(), parm.data(), parm.length(), &error); if (error) ServerInstance->Logs.Debug(MODNAME, "BUG: Apparently PQescapeStringConn() failed"); - res.append(&buffer[0], escapedsize); + res.append(buffer.data(), escapedsize); } } } diff --git a/src/modules/extra/m_regex_posix.cpp b/src/modules/extra/m_regex_posix.cpp index 819046e2b..7476039cd 100644 --- a/src/modules/extra/m_regex_posix.cpp +++ b/src/modules/extra/m_regex_posix.cpp @@ -51,10 +51,10 @@ public: std::vector errormsg(errorsize); // Retrieve the error message and free the buffer. - regerror(error, ®ex, &errormsg[0], errormsg.size()); + regerror(error, ®ex, errormsg.data(), errormsg.size()); regfree(®ex); - throw Regex::Exception(mod, pattern, std::string(&errormsg[0], errormsg.size() - 1)); + throw Regex::Exception(mod, pattern, std::string(errormsg.data(), errormsg.size() - 1)); } ~POSIXPattern() override @@ -70,7 +70,7 @@ public: std::optional Matches(const std::string& text) override { std::vector matches(32); - int result = regexec(®ex, text.c_str(), matches.size(), &matches[0], 0); + int result = regexec(®ex, text.c_str(), matches.size(), matches.data(), 0); if (result) return std::nullopt; diff --git a/src/modules/extra/m_regex_re2.cpp b/src/modules/extra/m_regex_re2.cpp index 068be5049..7874564cc 100644 --- a/src/modules/extra/m_regex_re2.cpp +++ b/src/modules/extra/m_regex_re2.cpp @@ -37,7 +37,7 @@ class RE2Pattern final private: RE2 regex; - RE2::Options BuildOptions(uint8_t options) + static RE2::Options BuildOptions(uint8_t options) { RE2::Options re2options; re2options.set_case_sensitive(!(options & Regex::OPT_CASE_INSENSITIVE)); @@ -62,7 +62,7 @@ public: std::optional Matches(const std::string& text) override { std::vector re2captures(regex.NumberOfCapturingGroups() + 1); - bool result = regex.Match(text, 0, text.length(), RE2::ANCHOR_BOTH, &re2captures[0], static_cast(re2captures.size())); + bool result = regex.Match(text, 0, text.length(), RE2::ANCHOR_BOTH, re2captures.data(), static_cast(re2captures.size())); if (!result) return std::nullopt; diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index b21ce982f..d1f31817c 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -229,7 +229,7 @@ namespace GnuTLS gnutls_x509_crt_deinit(cert); } - gnutls_x509_crt_t* raw() { return &certs[0]; } + gnutls_x509_crt_t* raw() { return certs.data(); } size_t size() const { return certs.size(); } }; @@ -983,15 +983,15 @@ public: unsigned int nameType = GNUTLS_NAME_DNS; // First, determine the size of the hostname. - if (gnutls_server_name_get(sess, &nameBuffer[0], &nameLength, &nameType, 0) != GNUTLS_E_SHORT_MEMORY_BUFFER) + if (gnutls_server_name_get(sess, nameBuffer.data(), &nameLength, &nameType, 0) != GNUTLS_E_SHORT_MEMORY_BUFFER) return false; // Then retrieve the hostname. nameBuffer.resize(nameLength); - if (gnutls_server_name_get(sess, &nameBuffer[0], &nameLength, &nameType, 0) != GNUTLS_E_SUCCESS) + if (gnutls_server_name_get(sess, nameBuffer.data(), &nameLength, &nameType, 0) != GNUTLS_E_SUCCESS) return false; - out.append(&nameBuffer[0]); + out.append(nameBuffer.data()); return true; } diff --git a/src/modules/m_abbreviation.cpp b/src/modules/m_abbreviation.cpp index dfed73020..4517e6a45 100644 --- a/src/modules/m_abbreviation.cpp +++ b/src/modules/m_abbreviation.cpp @@ -51,7 +51,8 @@ public: /* Look for any command that starts with the same characters, if it does, replace the command string with it */ size_t clen = command.length() - 1; - std::string foundcommand, matchlist; + std::string foundcommand; + std::string matchlist; bool foundmatch = false; for (const auto& [cmdname, _] : ServerInstance->Parser.GetCommands()) { diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 621fa4f04..ea8be2c41 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -119,7 +119,7 @@ public: { } - std::string GetVar(std::string varname, const std::string &original_line) + static std::string GetVar(std::string varname, const std::string &original_line) { irc::spacesepstream ss(original_line); varname.erase(varname.begin()); @@ -144,7 +144,7 @@ public: return word; } - std::string CreateRFCMessage(const std::string& command, CommandBase::Params& parameters) + static std::string CreateRFCMessage(const std::string& command, CommandBase::Params& parameters) { std::string message(command); for (CommandBase::Params::const_iterator iter = parameters.begin(); iter != parameters.end();) @@ -377,7 +377,8 @@ public: irc::tokenstream ss(result); CommandBase::Params pars; - std::string command, token; + std::string command; + std::string token; ss.GetMiddle(command); while (ss.GetTrailing(token)) diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp index e9bd3d45e..beb29f2ec 100644 --- a/src/modules/m_anticaps.cpp +++ b/src/modules/m_anticaps.cpp @@ -52,7 +52,7 @@ class AntiCapsMode final : public ParamMode> { private: - bool ParseMethod(irc::sepstream& stream, AntiCapsMethod& method) + static bool ParseMethod(irc::sepstream& stream, AntiCapsMethod& method) { std::string methodstr; if (!stream.GetToken(methodstr)) @@ -74,7 +74,7 @@ private: return true; } - bool ParseMinimumLength(irc::sepstream& stream, uint16_t& minlen) + static bool ParseMinimumLength(irc::sepstream& stream, uint16_t& minlen) { std::string minlenstr; if (!stream.GetToken(minlenstr)) @@ -88,7 +88,7 @@ private: return true; } - bool ParsePercent(irc::sepstream& stream, uint8_t& percent) + static bool ParsePercent(irc::sepstream& stream, uint8_t& percent) { std::string percentstr; if (!stream.GetToken(percentstr)) @@ -176,7 +176,7 @@ private: ServerInstance->Modes.Process(ServerInstance->FakeClient, channel, nullptr, changelist); } - void InformUser(Channel* channel, User* user, const std::string& message) + static void InformUser(Channel* channel, User* user, const std::string& message) { user->WriteNumeric(Numerics::CannotSendTo(channel, message + " and was blocked.")); } diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp index a7b3d0804..566171fe5 100644 --- a/src/modules/m_auditorium.cpp +++ b/src/modules/m_auditorium.cpp @@ -118,10 +118,7 @@ public: // Can you see the list by permission? ModResult res = CheckExemption::Call(exemptionprov, issuer, memb->chan, "auditorium-see"); - if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE)) - return true; - - return false; + return res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE); } ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) override diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index dca983b3e..dc03eddb2 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -42,7 +42,7 @@ public: syntax = ":"; } - PrefixMode* FindMode(const std::string& mid) + static PrefixMode* FindMode(const std::string& mid) { if (mid.length() == 1) return ServerInstance->Modes.FindPrefixMode(mid[0]); diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp index 9234c1b6f..b9bfab626 100644 --- a/src/modules/m_banexception.cpp +++ b/src/modules/m_banexception.cpp @@ -89,7 +89,8 @@ public: for (const ListModeBase::ListItem& ban : *list) { bool inverted; - std::string name, value; + std::string name; + std::string value; if (!ExtBan::Parse(ban.mask, name, value, inverted)) continue; diff --git a/src/modules/m_bcrypt.cpp b/src/modules/m_bcrypt.cpp index 0e464081c..62e50db07 100644 --- a/src/modules/m_bcrypt.cpp +++ b/src/modules/m_bcrypt.cpp @@ -43,7 +43,7 @@ private: public: unsigned long rounds = 10; - std::string Generate(const std::string& data, const std::string& salt) + static std::string Generate(const std::string& data, const std::string& salt) { char hash[64]; _crypt_blowfish_rn(data.c_str(), salt.c_str(), hash, sizeof(hash)); diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp index e810aed2c..57099b257 100644 --- a/src/modules/m_cban.cpp +++ b/src/modules/m_cban.cpp @@ -127,7 +127,7 @@ public: return CmdResult::FAILURE; } const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied"; - CBan* r = new CBan(ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str()); + CBan* r = new CBan(ServerInstance->Time(), duration, user->nick, reason, parameters[0]); if (ServerInstance->XLines->AddLine(r, user)) { diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index ede792d42..ea3243272 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -41,7 +41,7 @@ private: User* const user; const std::string& target; - std::string FormatTime(time_t ts) + static std::string FormatTime(time_t ts) { std::string timestr(InspIRCd::TimeString(ts, "%Y-%m-%d %H:%M:%S UTC (", true)); timestr.append(ConvToStr(ts)); diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index c8a8cfaa2..c8766478f 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -241,7 +241,7 @@ public: * @param domainparts The number of domain labels that should be visible. * @return The visible segment of the hostname. */ - std::string VisibleDomainParts(const std::string& host, unsigned int domainparts) + static std::string VisibleDomainParts(const std::string& host, unsigned int domainparts) { // The position at which we found the last dot. std::string::const_reverse_iterator dotpos; @@ -302,8 +302,11 @@ public: std::string SegmentIP(const CloakInfo& info, const irc::sockets::sockaddrs& ip, bool full) { std::string bindata; - size_t hop1, hop2, hop3; - size_t len1, len2; + size_t hop1; + size_t hop2; + size_t hop3; + size_t len1; + size_t len2; std::string rv; if (ip.family() == AF_INET6) { diff --git a/src/modules/m_codepage.cpp b/src/modules/m_codepage.cpp index f72907bcf..e6ff7a919 100644 --- a/src/modules/m_codepage.cpp +++ b/src/modules/m_codepage.cpp @@ -198,7 +198,7 @@ private: hashmap.swap(newhash); } - void CheckDuplicateNick() + static void CheckDuplicateNick() { insp::flat_set duplicates; for (auto* user : ServerInstance->Users.GetLocalUsers()) @@ -211,7 +211,7 @@ private: } } - void CheckInvalidNick() + static void CheckInvalidNick() { for (auto* user : ServerInstance->Users.GetLocalUsers()) { diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index cf11e299e..535702101 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -47,7 +47,7 @@ private: time_t ignoreuntil = 0; std::string banmessage; - unsigned char GetRange(LocalUser* user) + unsigned char GetRange(LocalUser* user) const { int family = user->client_sa.family(); switch (family) diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index f113215f7..3384741f3 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -194,6 +194,7 @@ public: : Command(parent, "DCCALLOW", 0) , ext(Ext) { + allow_empty_last_param = false; syntax = { "[(+|-) [