summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-20 19:09:50 +0100
committerHaru <haru@dotalux.com>2016-03-20 18:32:08 +0100
commitddbaad9bbab30490a6b23ef74203f30d290aa17c (patch)
treef9b360a2dcabc68a2df1a20c79413298d384e60c /src
parentc6d056f106386523812cfa3d271c5a67d8e2a596 (diff)
downloadhercules-ddbaad9bbab30490a6b23ef74203f30d290aa17c.tar.gz
hercules-ddbaad9bbab30490a6b23ef74203f30d290aa17c.tar.bz2
hercules-ddbaad9bbab30490a6b23ef74203f30d290aa17c.tar.xz
hercules-ddbaad9bbab30490a6b23ef74203f30d290aa17c.zip
Added separate char* and const char* data types to union DBKey
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/common/db.c20
-rw-r--r--src/common/db.h1
2 files changed, 12 insertions, 9 deletions
diff --git a/src/common/db.c b/src/common/db.c
index 939456b76..bbcac4b33 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -678,19 +678,19 @@ static int db_is_key_null(enum DBType type, union DBKey key)
*/
static union DBKey db_dup_key(struct DBMap_impl *db, union DBKey key)
{
- char *str;
- size_t len;
-
DB_COUNTSTAT(db_dup_key);
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
- len = strnlen(key.str, db->maxlen);
- str = (char*)aMalloc(len + 1);
+ {
+ size_t len = strnlen(key.str, db->maxlen);
+ char *str = aMalloc(len + 1);
+
memcpy(str, key.str, len);
str[len] = '\0';
- key.str = str;
+ key.mutstr = str;
return key;
+ }
default:
return key;
@@ -710,7 +710,7 @@ static void db_dup_key_free(struct DBMap_impl *db, union DBKey key)
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
- aFree((char*)key.str);
+ aFree(key.mutstr);
return;
default:
@@ -1158,7 +1158,8 @@ static void db_release_key(union DBKey key, struct DBData data, enum DBReleaseOp
{
(void)data;//not used
DB_COUNTSTAT(db_release_key);
- if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
+ if (which&DB_RELEASE_KEY)
+ aFree(key.mutstr); // FIXME: Ensure this is the right db type.
}
/**
@@ -1197,7 +1198,8 @@ static void db_release_data(union DBKey key, struct DBData data, enum DBReleaseO
static void db_release_both(union DBKey key, struct DBData data, enum DBReleaseOption which)
{
DB_COUNTSTAT(db_release_both);
- if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
+ if (which&DB_RELEASE_KEY)
+ aFree(key.mutstr); // FIXME: Ensure this is the right db type.
if (which&DB_RELEASE_DATA && data.type == DB_DATA_PTR) {
aFree(data.u.ptr);
data.u.ptr = NULL;
diff --git a/src/common/db.h b/src/common/db.h
index 60b5b32ac..d7d111c86 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -170,6 +170,7 @@ union DBKey {
int i;
unsigned int ui;
const char *str;
+ char *mutstr;
int64 i64;
uint64 ui64;
};