From 64f446220da6f567c818d00a650f92d25391d6e5 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 14 Jun 2021 20:57:58 +0200 Subject: fix warnings --- src/tree.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b8ff981..3bc513b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -17,10 +17,11 @@ static int string_compare ( const char* _1, const char* _2 ); * */ static int string_compare ( const char* _1, const char* _2 ) { + int i; + if ( !_1 || !_2 ) return 99; - int i; for (i = 0; _1[i] && _2[i]; i++) { char c1 = _1[i]; char c2 = _2[i]; @@ -76,8 +77,11 @@ int tree_insert ( tree_node_t** _root, char* _key, void* _data ) int tree_balanced_insert ( tree_node_t** _root, void* _data[], char* _key[], unsigned int _len) { - unsigned int i = 0, o = 0; - unsigned int n = 0; + unsigned int i, o, n, virtual_len, indices_cnt; + unsigned int* indices; + + indices = NULL; + indices_cnt = 0; /* * n is the smallest n, for which 2^(n+1) - 1 >= _len, @@ -87,10 +91,12 @@ int tree_balanced_insert ( tree_node_t** _root, void* _data[], char* _key[], un for (n = 0; pow( 2, n+1 ) - 1 < _len; n++){} /* The maximum size of a tree with depth n; */ - unsigned int virtual_len = pow( 2, n+1 ) - 1; + virtual_len = pow( 2, n+1 ) - 1; - unsigned int indices[ virtual_len ]; - unsigned int indices_cnt = 0; + indices = malloc( virtual_len * sizeof(unsigned int) ); + + if(!indices) + return -1; LOGPRINTF(_LOG_DEBUG, "Elements: %u Rounded size: %u Optimal depth: %u", _len, virtual_len, n); @@ -114,6 +120,9 @@ int tree_balanced_insert ( tree_node_t** _root, void* _data[], char* _key[], un } } + free( indices ); + indices = NULL; + return 0; } -- cgit v1.2.3