Committer: Mircea Gherzan <mircea.gherzan@xxxxxxxxxxxxxx> Date: 30/05/2010 at 22:38:29 Revision: 4634 Revision-id: mircea.gherzan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Branch nick: trunk Log: lib: core: fix signedness issues in haschain_store. Modified: M lib/core/hashchain_store.c M lib/core/hashchain_store.h === modified file 'lib/core/hashchain_store.c' --- lib/core/hashchain_store.c 2010-04-16 01:36:19 +0000 +++ lib/core/hashchain_store.c 2010-05-30 19:37:27 +0000 @@ -134,7 +134,8 @@ int hcstore_register_function(hchain_store_t *hcstore, const hash_function_t hash_function) { - int err = 0, i; + int err = 0; + unsigned i; HIP_ASSERT(hcstore != NULL); HIP_ASSERT(hash_function != NULL); @@ -175,10 +176,11 @@ int hcstore_register_hash_length(hchain_store_t *hcstore, const int function_id, const int hash_length) { - int err = 0, i; + int err = 0; + unsigned i; HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length > 0); // first check that there's still some space left @@ -187,7 +189,7 @@ // also check if the hash length is already stored for this function for (i = 0; i < hcstore->num_hash_lengths[function_id]; i++) { - if (hcstore->hash_lengths[function_id][i] == hash_length) { + if ((int)hcstore->hash_lengths[function_id][i] == hash_length) { HIP_DEBUG("hchain store already contains this hash length\n"); err = i; @@ -220,12 +222,13 @@ const int hash_length_id, const int hitem_length) { - int err = 0, i; + int err = 0; + unsigned i; HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length_id >= 0 - && hash_length_id < hcstore->num_hash_lengths[function_id]); + && hash_length_id < (int)hcstore->num_hash_lengths[function_id]); HIP_ASSERT(hitem_length > 0); // first check that there's still some space left @@ -236,7 +239,7 @@ for (i = 0; i < hcstore->hchain_shelves[function_id][hash_length_id]. num_hchain_lengths; i++) { if (hcstore->hchain_shelves[function_id][hash_length_id].hchain_lengths[i] - == hitem_length) { + == (unsigned)hitem_length) { HIP_DEBUG("hchain store already contains this hchain length\n"); err = i; @@ -272,12 +275,13 @@ const int addtional_hierarchies) { int item_offset = -1; - int err = 0, i; + int err = 0; + unsigned i; HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length_id >= 0 - && hash_length_id < hcstore->num_hash_lengths[function_id]); + && hash_length_id < (int)hcstore->num_hash_lengths[function_id]); HIP_ASSERT(hitem_length > 0); HIP_ASSERT(addtional_hierarchies > 0); @@ -285,7 +289,7 @@ for (i = 0; i < hcstore->hchain_shelves[function_id][hash_length_id]. num_hchain_lengths; i++) { if (hcstore->hchain_shelves[function_id][hash_length_id].hchain_lengths[i] - == hitem_length) { + == (unsigned)hitem_length) { // set item_offset item_offset = i; @@ -337,13 +341,15 @@ hash_tree_t *htree = NULL; hash_tree_t *link_tree = NULL; hash_function_t hash_function = NULL; - int hash_length = 0, hchain_length = 0; - int create_hchains = 0; + int hash_length = 0; + int hchain_length = 0; + unsigned create_hchains = 0; hash_chain_t *tmp_hchain = NULL; hash_tree_t *tmp_htree = NULL; unsigned char *root = NULL; int root_length = 0; - int err = 0, i, j; + int err = 0; + unsigned i, j; // set necessary parameters hash_function = hcstore->hash_functions[hash_func_id]; @@ -478,7 +484,8 @@ */ int hcstore_refill(hchain_store_t *hcstore, const int use_hash_trees) { - int err = 0, i, j, g, h; + int err = 0; + unsigned i, j, g, h; HIP_ASSERT(hcstore != NULL); @@ -518,19 +525,20 @@ int item_offset = -1; void *stored_item = NULL; int hierarchy_level = 0; - int err = 0, i; + int err = 0; + unsigned i; HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length_id >= 0 - && hash_length_id < hcstore->num_hash_lengths[function_id]); + && hash_length_id < (int)hcstore->num_hash_lengths[function_id]); HIP_ASSERT(hchain_length > 0); // first find the correct hchain item for (i = 0; i < hcstore->hchain_shelves[function_id][hash_length_id]. num_hchain_lengths; i++) { if (hcstore->hchain_shelves[function_id][hash_length_id].hchain_lengths[i] - == hchain_length) { + == (unsigned)hchain_length) { // set item_offset item_offset = i; @@ -581,12 +589,13 @@ hash_chain_t *hchain = NULL; hash_tree_t *htree = NULL; void *stored_item = NULL; - int err = 0, i, j; + int err = 0; + unsigned i, j; HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length_id >= 0 - && hash_length_id < hcstore->num_hash_lengths[function_id]); + && hash_length_id < (int)hcstore->num_hash_lengths[function_id]); HIP_ASSERT(hierarchy_level >= 0); HIP_ASSERT(anchor != NULL); @@ -599,8 +608,8 @@ for (i = 0; i < hcstore->hchain_shelves[function_id][hash_length_id]. num_hchain_lengths; i++) { // look for the anchor at each hchain_length with the respective hierarchy level - HIP_ASSERT(hierarchy_level < hcstore->hchain_shelves[function_id][hash_length_id]. - num_hierarchies[i]); + HIP_ASSERT((unsigned)hierarchy_level < hcstore->hchain_shelves + [function_id][hash_length_id].num_hierarchies[i]); for (j = 0; j < hip_ll_get_size(&hcstore->hchain_shelves[function_id] [hash_length_id].hchains[i][hierarchy_level]); j++) { @@ -661,7 +670,7 @@ const int function_id) { HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); return hcstore->hash_functions[function_id]; } @@ -678,9 +687,9 @@ const int hash_length_id) { HIP_ASSERT(hcstore != NULL); - HIP_ASSERT(function_id >= 0 && function_id < hcstore->num_functions); + HIP_ASSERT(function_id >= 0 && function_id < (int)hcstore->num_functions); HIP_ASSERT(hash_length_id >= 0 - && hash_length_id < hcstore->num_hash_lengths[function_id]); + && hash_length_id < (int)hcstore->num_hash_lengths[function_id]); return hcstore->hash_lengths[function_id][hash_length_id]; } === modified file 'lib/core/hashchain_store.h' --- lib/core/hashchain_store.h 2010-03-18 21:15:21 +0000 +++ lib/core/hashchain_store.h 2010-05-30 19:37:27 +0000 @@ -33,31 +33,31 @@ typedef struct hchain_shelf { /* number of different hchain lengths currently used for this * (hash-function, hash_length)-combination */ - int num_hchain_lengths; + unsigned num_hchain_lengths; /* the different hchain lengths */ - int hchain_lengths[MAX_NUM_HCHAIN_LENGTH]; + unsigned hchain_lengths[MAX_NUM_HCHAIN_LENGTH]; /* number of hierarchies in this shelf */ - int num_hierarchies[MAX_NUM_HCHAIN_LENGTH]; + unsigned num_hierarchies[MAX_NUM_HCHAIN_LENGTH]; /* hchains with the respective hchain length */ - hip_ll_t hchains[MAX_NUM_HCHAIN_LENGTH][MAX_NUM_HIERARCHIES]; + hip_ll_t hchains[MAX_NUM_HCHAIN_LENGTH][MAX_NUM_HIERARCHIES]; } hchain_shelf_t; typedef struct hchain_store { /* determines at which volume a store item should be refilled */ - double refill_threshold; + double refill_threshold; /* number of hash structures stored per item, when it is full */ - int num_hchains_per_item; + unsigned num_hchains_per_item; /* amount of currently used hash-functions */ - int num_functions; + unsigned num_functions; /* pointer to the hash-function used to create and verify the hchain * * @note params: (in_buffer, in_length, out_buffer) * @note out_buffer should be size MAX_HASH_LENGTH */ hash_function_t hash_functions[MAX_FUNCTIONS]; /* amount of different hash_lengths per hash-function */ - int num_hash_lengths[MAX_FUNCTIONS]; + unsigned num_hash_lengths[MAX_FUNCTIONS]; /* length of the hashes, of which the respective hchain items consist */ - int hash_lengths[MAX_FUNCTIONS][MAX_NUM_HASH_LENGTH]; + unsigned hash_lengths[MAX_FUNCTIONS][MAX_NUM_HASH_LENGTH]; /* contains hchains and meta-information about how to process them */ hchain_shelf_t hchain_shelves[MAX_FUNCTIONS][MAX_NUM_HASH_LENGTH]; } hchain_store_t;