mirror of
https://github.com/anope/anope.git
synced 2026-07-06 04:33:14 +02:00
Avoid returning null when a config tag does not exist.
This invokes undefined behaviour on modern compilers.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
+4
-4
@@ -49,7 +49,7 @@ Block* Block::GetBlock(const Anope::string &bname, int num)
|
||||
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)
|
||||
@@ -116,7 +116,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;
|
||||
@@ -602,7 +602,7 @@ void Conf::Post(Conf *old)
|
||||
Block *Conf::GetModule(Module *m)
|
||||
{
|
||||
if (!m)
|
||||
return NULL;
|
||||
return &(Config->EmptyBlock);
|
||||
|
||||
return GetModule(m->name);
|
||||
}
|
||||
@@ -654,7 +654,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)
|
||||
|
||||
+2
-2
@@ -427,8 +427,8 @@ void Anope::Init(int ac, char **av)
|
||||
if (!getuid() && !getgid())
|
||||
{
|
||||
/* If we are configured to setuid later, don't issue a warning */
|
||||
Configuration::Block *options = Config->GetBlock("options");
|
||||
if (options->Get<const Anope::string>("user").empty())
|
||||
Configuration::Block *options = Config ? Config->GetBlock("options") : NULL;
|
||||
if (!options || options->Get<const Anope::string>("user").empty())
|
||||
{
|
||||
std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl;
|
||||
std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user