diff options
author | Naram Qashat cyberbotx@cyberbotx.com <Naram Qashat cyberbotx@cyberbotx.com@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-10-05 03:01:18 +0000 |
---|---|---|
committer | Naram Qashat cyberbotx@cyberbotx.com <Naram Qashat cyberbotx@cyberbotx.com@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-10-05 03:01:18 +0000 |
commit | 4e11583205327ce9d65c744473baff28d54979b3 (patch) | |
tree | 0cfa7dd3ecea5836b97c23cd4a4124f351a04ccb | |
parent | 70fc37073fe4034dfb728c8e2e183b55f969df8b (diff) |
Fix problems with using ValueContainerChar by creating a specialized template for ValueContainer.
Note: The solution uses new to allocate memory for the variable, we'll have to look into deleting the memory at shutdown, or replacing the char * variables with std::string.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1424 5417fbe8-f217-4b02-8779-1006273d7864
-rw-r--r-- | include/configreader.h | 26 | ||||
-rw-r--r-- | src/config.c | 12 |
2 files changed, 30 insertions, 8 deletions
diff --git a/include/configreader.h b/include/configreader.h index 2a40fd8ef..222195727 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -119,6 +119,32 @@ template<typename T> class ValueContainer : public ValueContainerBase } }; +/** This a specific version of ValueContainer to handle character arrays specially + */ +template<> class ValueContainer<char **> : public ValueContainerBase +{ + /** Contained item */ + char **val; + public: + /** Initialize with nothing */ + ValueContainer() : ValueContainerBase(), val(NULL) { } + /** Initialize with a value of type T */ + ValueContainer(char **Val) : ValueContainerBase(), val(Val) { } + /** Initialize with a copy */ + ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } + ValueContainer &operator=(const ValueContainer &Val) + { + val = Val.val; + return *this; + } + /** Change value to type T of size s */ + void Set(const char *newval, size_t s) + { + *val = new char[s]; + strlcpy(*val, newval, s); + } +}; + /** This a specific version of ValueContainer to handle std::string specially */ template<> class ValueContainer<std::string *> : public ValueContainerBase diff --git a/src/config.c b/src/config.c index 536a0d2f3..ddced7ed9 100644 --- a/src/config.c +++ b/src/config.c @@ -596,29 +596,25 @@ int ServerConfig::Read(bool bail) case DT_NOSPACES: { ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value); - char *tmp = vi.GetString(); - vcc->Set(&tmp, strlen(vi.GetString()) + 1); + vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); } break; case DT_HOSTNAME: { ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value); - char *tmp = vi.GetString(); - vcc->Set(&tmp, strlen(vi.GetString()) + 1); + vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); } break; case DT_IPADDRESS: { ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild); - char *tmp = vi.GetString(); - vcc->Set(&tmp, strlen(vi.GetString()) + 1); + vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); } break; case DT_CHARPTR: { ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val); // Make sure we also copy the null terminator - char *tmp = vi.GetString(); - vcc->Set(&tmp, strlen(vi.GetString()) + 1); + vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); } break; case DT_STRING: { |