summaryrefslogtreecommitdiff
path: root/src/common/db.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-01-20 04:36:08 +0100
committerHaru <haru@dotalux.com>2015-01-20 04:41:33 +0100
commit4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4 (patch)
treedab9d12a6a4b95a37598e27e6e86d6047360d61b /src/common/db.c
parent03709c136ad300be631adfd38dc36c2433bda718 (diff)
downloadhercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.gz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.bz2
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.xz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.zip
Minor fixes and tweaks suggested by cppcheck
- Variable scopes reduced - Parenthesized ambiguous expressions - Removed or added NULL checks where (un)necessary - Corrected format strings - Fixed typos potentially leading to bugs Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/db.c')
-rw-r--r--src/common/db.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/common/db.c b/src/common/db.c
index 044df19aa..69e2333a9 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -497,7 +497,6 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
DBNode *y = node;
DBNode *x = NULL;
DBNode *x_parent = NULL;
- DBNode *w;
DB_COUNTSTAT(db_rebalance_erase);
// Select where to change the tree
@@ -565,6 +564,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
// Restore the RED-BLACK properties
if (y->color != RED) {
while (x != *root && (x == NULL || x->color == BLACK)) {
+ DBNode *w;
if (x == x_parent->left) {
w = x_parent->right;
if (w->color == RED) {
@@ -1526,7 +1526,6 @@ static bool db_obj_exists(DBMap* self, DBKey key)
{
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
- int c;
bool found = false;
DB_COUNTSTAT(db_exists);
@@ -1548,7 +1547,7 @@ static bool db_obj_exists(DBMap* self, DBKey key)
db_free_lock(db);
node = db->ht[db->hash(key, db->maxlen)%HASH_SIZE];
while (node) {
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
db->cache = node;
@@ -1577,7 +1576,6 @@ static DBData* db_obj_get(DBMap* self, DBKey key)
{
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
- int c;
DBData *data = NULL;
DB_COUNTSTAT(db_get);
@@ -1600,7 +1598,7 @@ static DBData* db_obj_get(DBMap* self, DBKey key)
db_free_lock(db);
node = db->ht[db->hash(key, db->maxlen)%HASH_SIZE];
while (node) {
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
data = &node->data;
@@ -1970,7 +1968,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
unsigned int hash;
- int c = 0, retval = 0;
+ int retval = 0;
DB_COUNTSTAT(db_remove);
if (db == NULL) return 0; // nullpo candidate
@@ -1988,7 +1986,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
db_free_lock(db);
hash = db->hash(key, db->maxlen)%HASH_SIZE;
for(node = db->ht[hash]; node; ){
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
if (db->cache == node)