]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Avoid calling methods on NULL pointers wherever possible.
authorPeter Powell <petpow@saberuk.com>
Wed, 8 Oct 2014 15:34:37 +0000 (16:34 +0100)
committerPeter Powell <petpow@saberuk.com>
Mon, 13 Oct 2014 05:18:14 +0000 (06:18 +0100)
The trick we use to allow this is undefined behaviour and is not
liked by LLVM. We should stop using it but it has the potential to
break to many things for a minor release.

include/configreader.h
include/modules.h
src/commands/cmd_motd.cpp
src/commands/cmd_rules.cpp
src/configreader.cpp

index 1edacfe13291c1b65390b18bf1aa7b519d6dac4c..b01a979a7c2703384bb17155e52688370af0d3df 100644 (file)
@@ -197,6 +197,9 @@ class CoreExport ServerConfig
 
        ConfigTagList ConfTags(const std::string& tag);
 
+       /** An empty configuration tag. */
+       ConfigTag* EmptyTag;
+
        /** Error stream, contains error output from any failed configuration parsing.
         */
        std::stringstream errstr;
@@ -527,6 +530,8 @@ class CoreExport ServerConfig
         */
        ServerConfig();
 
+       ~ServerConfig();
+
        /** Get server ID as string with required leading zeroes
         */
        const std::string& GetSID();
index eef8c61c9836395e037cb839ea659991e3d5ad71..cd0d5aad01389b10d40e6620e85cf68de813a15d 100644 (file)
@@ -116,7 +116,7 @@ struct ModResult {
  * and numerical comparisons in preprocessor macros if they wish to support
  * multiple versions of InspIRCd in one file.
  */
-#define INSPIRCD_VERSION_API 8
+#define INSPIRCD_VERSION_API 9
 
 /**
  * This #define allows us to call a method in all
index 8e227723ee57f0bcca916fd1f66e85a4a6dcb241..869a9c3538652af4775da4791b742b4d325a26bf 100644 (file)
@@ -53,7 +53,7 @@ CmdResult CommandMotd::Handle (const std::vector<std::string>& parameters, User
        if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
                return CMD_SUCCESS;
 
-       ConfigTag* tag = NULL;
+       ConfigTag* tag = ServerInstance->Config->EmptyTag;
        if (IS_LOCAL(user))
                tag = user->GetClass()->config;
        std::string motd_name = tag->getString("motd", "motd");
index 5d41aa4b8db8e335cc97675d07e41dd59277dba7..17de9f3f2235ffcf7a6333383861702185158240 100644 (file)
@@ -51,7 +51,7 @@ CmdResult CommandRules::Handle (const std::vector<std::string>& parameters, User
        if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
                return CMD_SUCCESS;
 
-       ConfigTag* tag = NULL;
+       ConfigTag* tag = ServerInstance->Config->EmptyTag;
        if (IS_LOCAL(user))
                tag = user->GetClass()->config;
        std::string rules_name = tag->getString("rules", "rules");
index 060f66d1620249b4cfb9fb4a33e6099df8f876af..b5d2fdb16f8d3e16aa3eec6e37d903593976a8ef 100644 (file)
@@ -48,6 +48,14 @@ ServerConfig::ServerConfig()
        OperMaxChans = 30;
        c_ipv4_range = 32;
        c_ipv6_range = 128;
+
+       std::vector<KeyVal>* items;
+       EmptyTag = ConfigTag::create("empty", "<auto>", 0, items);
+}
+
+ServerConfig::~ServerConfig()
+{
+       delete EmptyTag;
 }
 
 void ServerConfig::Update005()
@@ -888,7 +896,7 @@ ConfigTag* ServerConfig::ConfValue(const std::string &tag)
 {
        ConfigTagList found = config_data.equal_range(tag);
        if (found.first == found.second)
-               return NULL;
+               return EmptyTag;
        ConfigTag* rv = found.first->second;
        found.first++;
        if (found.first != found.second)