Skip to content

Commit

Permalink
Fix gcc warnings related to C89 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
fragglet committed Dec 17, 2024
1 parent 3c91f7c commit ee67ef8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/rb-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
15 changes: 9 additions & 6 deletions src/sortedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions test/test-hash-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void test_hash_table_iterating(void)
{
HashTable *hash_table;
HashTableIterator iterator;
HashTablePair pair;
int count;

hash_table = generate_hash_table();
Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}
Expand Down

0 comments on commit ee67ef8

Please sign in to comment.