diff --git a/src/rb-tree.h b/src/rb-tree.h index 69447f4..143801e 100644 --- a/src/rb-tree.h +++ b/src/rb-tree.h @@ -107,7 +107,7 @@ typedef int (*RBTreeCompareFunc)(RBTreeValue data1, RBTreeValue data2); */ typedef enum { RB_TREE_NODE_RED, - RB_TREE_NODE_BLACK, + RB_TREE_NODE_BLACK } RBTreeNodeColor; /** diff --git a/src/sortedarray.c b/src/sortedarray.c index a45e7e7..be28d61 100644 --- a/src/sortedarray.c +++ b/src/sortedarray.c @@ -52,6 +52,9 @@ unsigned int sortedarray_length(SortedArray *array) SortedArray *sortedarray_new(unsigned int length, SortedArrayCompareFunc cmp_func) { + SortedArrayValue *array; + SortedArray *sortedarray; + if (cmp_func == NULL) { return NULL; } @@ -61,12 +64,12 @@ SortedArray *sortedarray_new(unsigned int length, length = 16; } - SortedArrayValue *array = malloc(sizeof(SortedArrayValue) * length); + array = malloc(sizeof(SortedArrayValue) * length); if (array == NULL) { return NULL; } - SortedArray *sortedarray = malloc(sizeof(SortedArray)); + sortedarray = malloc(sizeof(SortedArray)); if (sortedarray == NULL) { free(array); return NULL; @@ -118,6 +121,7 @@ int sortedarray_remove_range(SortedArray *sortedarray, unsigned int index, int sortedarray_insert(SortedArray *sortedarray, SortedArrayValue data) { unsigned int left, right, index; + int order; if (sortedarray == NULL) { return 0; @@ -132,9 +136,8 @@ int sortedarray_insert(SortedArray *sortedarray, SortedArrayValue data) while (left != right) { index = (left + right) / 2; + order = sortedarray->cmp_func(data, sortedarray->data[index]); - int order = - sortedarray->cmp_func(data, sortedarray->data[index]); if (order < 0) { /* value should be left of index */ right = index; @@ -186,6 +189,7 @@ int sortedarray_insert(SortedArray *sortedarray, SortedArrayValue data) int sortedarray_index_of(SortedArray *sortedarray, SortedArrayValue data) { unsigned int left, right, index; + int order; if (sortedarray == NULL) { return -1; @@ -200,9 +204,8 @@ int sortedarray_index_of(SortedArray *sortedarray, SortedArrayValue data) while (left != right) { index = (left + right) / 2; + order = sortedarray->cmp_func(data, sortedarray->data[index]); - int order = - sortedarray->cmp_func(data, sortedarray->data[index]); if (order < 0) { /* value should be left */ right = index; diff --git a/test/test-hash-table.c b/test/test-hash-table.c index 26d6b7b..9e86fdf 100644 --- a/test/test-hash-table.c +++ b/test/test-hash-table.c @@ -166,6 +166,7 @@ void test_hash_table_iterating(void) { HashTable *hash_table; HashTableIterator iterator; + HashTablePair pair; int count; hash_table = generate_hash_table(); @@ -184,7 +185,7 @@ void test_hash_table_iterating(void) assert(count == NUM_TEST_VALUES); /* Test iter_next after iteration has completed. */ - HashTablePair pair = hash_table_iter_next(&iterator); + pair = hash_table_iter_next(&iterator); assert(pair.value == HASH_TABLE_NULL); hash_table_free(hash_table); @@ -397,6 +398,8 @@ void test_hash_iterator_key_pair() HashTable *hash_table; HashTableIterator iterator; HashTablePair pair; + int *key, *val; + hash_table = hash_table_new(int_hash, int_equal); /* Add some values */ @@ -410,8 +413,8 @@ void test_hash_iterator_key_pair() /* Retrieve both Key and Value */ pair = hash_table_iter_next(&iterator); - int *key = (int *) pair.key; - int *val = (int *) pair.value; + key = (int *) pair.key; + val = (int *) pair.value; assert(*key == *val); }