diff options
author | Sadie Powell <sadie@witchery.services> | 2021-11-30 10:54:10 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2021-11-30 11:04:19 +0000 |
commit | 754c82d047b80c30ff2f775d32e8b9b054049ebd (patch) | |
tree | eb1abbc79af82320c34805c8282914609476a973 /src | |
parent | 17fa704278a99aeac4e59df1bf58e63d88357788 (diff) |
Remove undefined behaviour around checking if this is null.
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 2 | ||||
-rw-r--r-- | src/config.cpp | 27 | ||||
-rw-r--r-- | src/regchannel.cpp | 3 |
3 files changed, 8 insertions, 24 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index b2af559ae..77f23ea45 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -912,7 +912,7 @@ bool Channel::CheckKick(User *user) return false; if (mask.empty()) - mask = this->ci->GetIdealBan(user); + mask = this->ci ? this->ci->GetIdealBan(user) : "*!*@" + user->GetDisplayedHost(); if (reason.empty()) reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN); diff --git a/src/config.cpp b/src/config.cpp index e55defb47..db574584f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -33,47 +33,32 @@ const Anope::string &Block::GetName() const int Block::CountBlock(const Anope::string &bname) { - if (!this) - return 0; - return blocks.count(bname); } Block* Block::GetBlock(const Anope::string &bname, int num) { - if (!this) - return NULL; - std::pair<block_map::iterator, block_map::iterator> it = blocks.equal_range(bname); for (int i = 0; it.first != it.second; ++it.first, ++i) if (i == num) return &it.first->second; - return NULL; + return &(Config->EmptyBlock); } bool Block::Set(const Anope::string &tag, const Anope::string &value) { - if (!this) - return false; - items[tag] = value; return true; } -const Block::item_map* Block::GetItems() const +const Block::item_map& Block::GetItems() const { - if (this) - return &items; - else - return NULL; + return items; } template<> const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const { - if (!this) - return def; - Anope::map<Anope::string>::const_iterator it = items.find(tag); if (it != items.end()) return it->second; @@ -110,7 +95,7 @@ template<typename T> static void ValidateNotZero(const Anope::string &block, con throw ConfigException("The value for <" + block + ":" + name + "> cannot be zero!"); } -Conf::Conf() : Block("") +Conf::Conf() : Block(""), EmptyBlock("") { ReadTimeout = 0; UsePrivmsg = DefPrivmsg = false; @@ -596,7 +581,7 @@ void Conf::Post(Conf *old) Block *Conf::GetModule(Module *m) { if (!m) - return NULL; + return &(Config->EmptyBlock); return GetModule(m->name); } @@ -648,7 +633,7 @@ Block *Conf::GetCommand(CommandSource &source) return b; } - return NULL; + return &(Config->EmptyBlock); } File::File(const Anope::string &n, bool e) : name(n), executable(e), fp(NULL) diff --git a/src/regchannel.cpp b/src/regchannel.cpp index bd6fcbbf0..ffdf55bce 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -629,8 +629,7 @@ void ChannelInfo::ClearLevels() Anope::string ChannelInfo::GetIdealBan(User *u) const { - int bt = this ? this->bantype : -1; - switch (bt) + switch (this->bantype) { case 0: return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost(); |