Skip to content

Commit

Permalink
Eliminate compiler warnings found by GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
fmela committed Apr 12, 2015
1 parent 999da92 commit e913d32
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 53 deletions.
4 changes: 2 additions & 2 deletions demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ main(int argc, char **argv)
if (inserted) {
*datum_location = xstrdup(ptr2);
printf("inserted '%s': '%s'\n",
ptr, *datum_location);
ptr, (char *)*datum_location);
} else {
printf("'%s' already in dict: '%s'\n",
ptr, *datum_location);
ptr, (char *)*datum_location);
}
} else if (strcmp(buf, "search") == 0) {
if (ptr2) {
Expand Down
8 changes: 3 additions & 5 deletions src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ hashtable_resize(hashtable* table, unsigned new_size)
if (table->size == new_size)
return true;

/* TODO: use REALLOC instead of MALLOC. */
/* TODO: investigate whether using realloc would be advantageous. */
hash_node** ntable = MALLOC(new_size * sizeof(hash_node*));
if (!ntable)
return false;
Expand Down Expand Up @@ -489,8 +489,7 @@ hashtable_itor_next(hashtable_itor* itor)
if (!itor->node)
return hashtable_itor_first(itor);

itor->node = itor->node->next;
if (itor->node)
if ((itor->node = itor->node->next) != NULL)
return true;

unsigned slot = itor->slot;
Expand All @@ -514,8 +513,7 @@ hashtable_itor_prev(hashtable_itor* itor)
if (!itor->node)
return hashtable_itor_last(itor);

itor->node = itor->node->prev;
if (itor->node)
if ((itor->node = itor->node->prev) != NULL)
return true;

unsigned slot = itor->slot;
Expand Down
8 changes: 4 additions & 4 deletions src/hashtable2.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ hashtable2_insert(hashtable2* table, void* key, bool* inserted)
}
}
const unsigned raw_hash = table->hash_func(key);
const unsigned hash = (raw_hash == 0) ? -1 : raw_hash;
const unsigned hash = (raw_hash == 0) ? ~(unsigned)0 : raw_hash;
void **datum_location = insert(table, key, hash, inserted);
ASSERT(datum_location != NULL);
return datum_location;
Expand All @@ -239,7 +239,7 @@ hashtable2_search(hashtable2* table, const void* key)
ASSERT(table != NULL);

const unsigned raw_hash = table->hash_func(key);
const unsigned hash = (raw_hash == 0) ? -1 : raw_hash;
const unsigned hash = (raw_hash == 0) ? ~(unsigned)0 : raw_hash;
const unsigned truncated_hash = hash % table->size;
unsigned index = truncated_hash;
do {
Expand Down Expand Up @@ -309,7 +309,7 @@ hashtable2_remove(hashtable2* table, const void* key)
ASSERT(table != NULL);

const unsigned raw_hash = table->hash_func(key);
const unsigned hash = (raw_hash == 0) ? -1 : raw_hash;
const unsigned hash = (raw_hash == 0) ? ~(unsigned)0 : raw_hash;
const unsigned truncated_hash = hash % table->size;
unsigned index = truncated_hash;
do {
Expand Down Expand Up @@ -603,7 +603,7 @@ bool
hashtable2_itor_search(hashtable2_itor* itor, const void* key)
{
const unsigned raw_hash = itor->table->hash_func(key);
const unsigned hash = (raw_hash == 0) ? -1 : raw_hash;
const unsigned hash = (raw_hash == 0) ? ~(unsigned)0 : raw_hash;
const unsigned truncated_hash = hash % itor->table->size;
unsigned index = truncated_hash;
do {
Expand Down
2 changes: 1 addition & 1 deletion src/rb_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ node_new(void* key)
{
rb_node* node = MALLOC(sizeof(*node));
if (node) {
ASSERT((((intptr_t)node) & 1) == 0);
ASSERT((((intptr_t)node) & 1) == 0); /* Ensure malloc returns aligned result. */
node->key = key;
node->datum = NULL;
node->parent = RB_NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/skiplist.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,5 +568,5 @@ static unsigned
rand_link_count(skiplist* list)
{
unsigned count = __builtin_ctz(dict_rand()) / 2 + 1;
return (count >= list->max_link) ? list->max_link - 1 : count;
return (count >= list->max_link) ? list->max_link - 1 : count;
}
80 changes: 40 additions & 40 deletions src/tree_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ tree_search_node(void* Tree, const void* key)
{
ASSERT(Tree != NULL);

tree* tree = Tree;
for (tree_node* node = tree->root; node;) {
int cmp = tree->cmp_func(key, node->key);
tree* t = Tree;
for (tree_node* node = t->root; node;) {
int cmp = t->cmp_func(key, node->key);
if (cmp < 0)
node = node->llink;
else if (cmp)
Expand All @@ -173,11 +173,11 @@ tree_search(void* Tree, const void* key)
void*
tree_search_le_node(void* Tree, const void* key)
{
tree* tree = Tree;
ASSERT(tree != NULL);
tree_node* node = tree->root, *ret = NULL;
tree* t = Tree;
ASSERT(t != NULL);
tree_node* node = t->root, *ret = NULL;
while (node) {
int cmp = tree->cmp_func(key, node->key);
int cmp = t->cmp_func(key, node->key);
if (cmp == 0)
return node;
if (cmp < 0) {
Expand All @@ -201,11 +201,11 @@ tree_search_le(void* Tree, const void* key)
void*
tree_search_lt_node(void* Tree, const void* key)
{
tree* tree = Tree;
ASSERT(tree != NULL);
tree_node* node = tree->root, *ret = NULL;
tree* t = Tree;
ASSERT(t != NULL);
tree_node* node = t->root, *ret = NULL;
while (node) {
int cmp = tree->cmp_func(key, node->key);
int cmp = t->cmp_func(key, node->key);
if (cmp <= 0) {
node = node->llink;
} else {
Expand All @@ -227,11 +227,11 @@ tree_search_lt(void* Tree, const void* key)
void*
tree_search_ge_node(void* Tree, const void* key)
{
tree* tree = Tree;
ASSERT(tree != NULL);
tree_node* node = tree->root, *ret = NULL;
tree* t = Tree;
ASSERT(t != NULL);
tree_node* node = t->root, *ret = NULL;
while (node) {
int cmp = tree->cmp_func(key, node->key);
int cmp = t->cmp_func(key, node->key);
if (cmp == 0) {
return node;
}
Expand All @@ -256,11 +256,11 @@ tree_search_ge(void* Tree, const void* key)
void*
tree_search_gt_node(void* Tree, const void* key)
{
tree* tree = Tree;
ASSERT(tree != NULL);
tree_node* node = tree->root, *ret = NULL;
tree* t = Tree;
ASSERT(t != NULL);
tree_node* node = t->root, *ret = NULL;
while (node) {
int cmp = tree->cmp_func(key, node->key);
int cmp = t->cmp_func(key, node->key);
if (cmp < 0) {
ret = node;
node = node->llink;
Expand All @@ -284,10 +284,10 @@ tree_min(const void* Tree)
{
ASSERT(Tree != NULL);

const tree* tree = Tree;
if (!tree->root)
const tree* t = Tree;
if (!t->root)
return NULL;
const tree_node* node = tree->root;
const tree_node* node = t->root;
while (node->llink)
node = node->llink;
return node->key;
Expand All @@ -298,10 +298,10 @@ tree_max(const void* Tree)
{
ASSERT(Tree != NULL);

const tree* tree = Tree;
if (!tree->root)
const tree* t = Tree;
if (!t->root)
return NULL;
const tree_node* node = tree->root;
const tree_node* node = t->root;
while (node->rlink)
node = node->rlink;
return node->key;
Expand All @@ -313,10 +313,10 @@ tree_traverse(void* Tree, dict_visit_func visit)
ASSERT(Tree != NULL);
ASSERT(visit != NULL);

tree* tree = Tree;
tree* t = Tree;
size_t count = 0;
if (tree->root) {
tree_node* node = tree_node_min(tree->root);
if (t->root) {
tree_node* node = tree_node_min(t->root);
do {
++count;
if (!visit(node->key, node->datum))
Expand Down Expand Up @@ -355,12 +355,12 @@ tree_clear(void* Tree)
{
ASSERT(Tree != NULL);

tree* tree = Tree;
const size_t count = tree->count;
if (tree->root) {
tree_node_free(tree, tree->root);
tree->root = NULL;
tree->count = 0;
tree* t = Tree;
const size_t count = t->count;
if (t->root) {
tree_node_free(t, t->root);
t->root = NULL;
t->count = 0;
}
return count;
}
Expand Down Expand Up @@ -429,9 +429,9 @@ node_min_leaf_depth(const tree_node* node, size_t depth)
size_t
tree_min_leaf_depth(const void* Tree)
{
const tree* tree = Tree;
ASSERT(tree != NULL);
return tree->root ? node_min_leaf_depth(tree->root, 1) : 0;
const tree* t = Tree;
ASSERT(t != NULL);
return t->root ? node_min_leaf_depth(t->root, 1) : 0;
}

static size_t
Expand All @@ -454,9 +454,9 @@ node_max_leaf_depth(const tree_node* node, size_t depth)
size_t
tree_max_leaf_depth(const void* Tree)
{
const tree* tree = Tree;
ASSERT(tree != NULL);
return tree->root ? node_max_leaf_depth(tree->root, 1) : 0;
const tree* t = Tree;
ASSERT(t != NULL);
return t->root ? node_max_leaf_depth(t->root, 1) : 0;
}

bool
Expand Down

0 comments on commit e913d32

Please sign in to comment.