1
0
mirror of https://github.com/anope/anope.git synced 2026-07-01 06:36:39 +02:00

Remove undefined behaviour around checking if this is null.

This commit is contained in:
Sadie Powell
2021-11-30 10:54:10 +00:00
parent 17fa704278
commit 754c82d047
6 changed files with 17 additions and 35 deletions
-2
View File
@@ -21,8 +21,6 @@ set(DEFAULT_INCLUDE_DIRS)
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.2)
message(FATAL_ERROR "Your compiler is too old to build Anope. Upgrade to GCC 4.2 or newer!")
elseif(CMAKE_CXX_COMPILER_ID VERSION_GREATER_EQUAL 6.0)
set(CXXFLAGS "${CXXFLAGS} -fno-delete-null-pointer-checks")
endif()
endif()
+4 -1
View File
@@ -60,7 +60,7 @@ namespace Configuration
}
bool Set(const Anope::string &tag, const Anope::string &value);
const item_map* GetItems() const;
const item_map &GetItems() const;
};
template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const;
@@ -129,6 +129,9 @@ namespace Configuration
std::map<Anope::string, Block *> modules;
Anope::map<Anope::string> bots;
/* Represents a missing tag. */
Block EmptyBlock;
Conf();
~Conf();
+5 -8
View File
@@ -57,15 +57,12 @@ class CommandOSConfig : public Command
for (unsigned i = 0; !show_blocks[i].empty(); ++i)
{
Configuration::Block *block = Config->GetBlock(show_blocks[i]);
const Configuration::Block::item_map *items = block->GetItems();
if (!items)
continue;
const Configuration::Block::item_map &items = block->GetItems();
ListFormatter lflist(source.GetAccount());
lflist.AddColumn(_("Name")).AddColumn(_("Value"));
for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
{
ListFormatter::ListEntry entry;
entry["Name"] = it->first;
@@ -90,15 +87,15 @@ class CommandOSConfig : public Command
for (int i = 0; i < Config->CountBlock("module"); ++i)
{
Configuration::Block *block = Config->GetBlock("module", i);
const Configuration::Block::item_map *items = block->GetItems();
const Configuration::Block::item_map &items = block->GetItems();
if (!items || items->size() <= 1)
if (items.size() <= 1)
continue;
ListFormatter::ListEntry entry;
entry["Module Name"] = block->Get<Anope::string>("name");
for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
{
entry["Name"] = it->first;
entry["Value"] = it->second;
+1 -1
View File
@@ -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);
+6 -21
View File
@@ -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)
+1 -2
View File
@@ -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();