Skip to content

Commit

Permalink
Revert "Fix gcc warnings related to C89 compliance"
Browse files Browse the repository at this point in the history
This reverts commit ee67ef8.
  • Loading branch information
fragglet committed Dec 17, 2024
1 parent ca6c41e commit 0d80812
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 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: 6 additions & 9 deletions src/sortedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ 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 @@ -64,12 +61,12 @@ SortedArray *sortedarray_new(unsigned int length,
length = 16;
}

array = malloc(sizeof(SortedArrayValue) * length);
SortedArrayValue *array = malloc(sizeof(SortedArrayValue) * length);
if (array == NULL) {
return NULL;
}

sortedarray = malloc(sizeof(SortedArray));
SortedArray *sortedarray = malloc(sizeof(SortedArray));
if (sortedarray == NULL) {
free(array);
return NULL;
Expand Down Expand Up @@ -121,7 +118,6 @@ 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 @@ -136,8 +132,9 @@ 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 @@ -189,7 +186,6 @@ 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 @@ -204,8 +200,9 @@ 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: 3 additions & 6 deletions test/test-hash-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ void test_hash_table_iterating(void)
{
HashTable *hash_table;
HashTableIterator iterator;
HashTablePair pair;
int count;

hash_table = generate_hash_table();
Expand All @@ -185,7 +184,7 @@ void test_hash_table_iterating(void)
assert(count == NUM_TEST_VALUES);

/* Test iter_next after iteration has completed. */
pair = hash_table_iter_next(&iterator);
HashTablePair pair = hash_table_iter_next(&iterator);
assert(pair.value == HASH_TABLE_NULL);

hash_table_free(hash_table);
Expand Down Expand Up @@ -398,8 +397,6 @@ 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 @@ -413,8 +410,8 @@ void test_hash_iterator_key_pair()
/* Retrieve both Key and Value */
pair = hash_table_iter_next(&iterator);

key = (int *) pair.key;
val = (int *) pair.value;
int *key = (int *) pair.key;
int *val = (int *) pair.value;

assert(*key == *val);
}
Expand Down

0 comments on commit 0d80812

Please sign in to comment.