From 0a140c4a29363442ebc51be3acddc903c249d17c Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 24 May 2017 02:13:58 +0200 Subject: [PATCH] reduce the scope of some variables to please codacy --- examples/msg/dht-kademlia/answer.c | 11 +++++------ examples/msg/dht-kademlia/dht-kademlia.c | 3 +-- include/xbt/str.h | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/msg/dht-kademlia/answer.c b/examples/msg/dht-kademlia/answer.c index 1cd48a0cf9..6fb5f75de2 100644 --- a/examples/msg/dht-kademlia/answer.c +++ b/examples/msg/dht-kademlia/answer.c @@ -109,15 +109,14 @@ void answer_trim(answer_t answer) */ void answer_add_bucket(bucket_t bucket, answer_t answer) { - unsigned int cpt; - unsigned int id; - unsigned int distance; - node_contact_t contact; xbt_assert((bucket != NULL), "Provided a NULL bucket"); xbt_assert((bucket->nodes != NULL), "Provided a bucket which nodes are NULL"); + + unsigned int cpt; + unsigned int id; xbt_dynar_foreach(bucket->nodes, cpt, id) { - distance = id ^ answer->destination_id; - contact = node_contact_new(id, distance); + unsigned int distance = id ^ answer->destination_id; + node_contact_t contact = node_contact_new(id, distance); xbt_dynar_push(answer->nodes, &contact); answer->size++; } diff --git a/examples/msg/dht-kademlia/dht-kademlia.c b/examples/msg/dht-kademlia/dht-kademlia.c index 463fd01338..439ad0f7dc 100644 --- a/examples/msg/dht-kademlia/dht-kademlia.c +++ b/examples/msg/dht-kademlia/dht-kademlia.c @@ -360,11 +360,10 @@ unsigned int send_find_node_to_best(node_t node, answer_t node_list) unsigned int i = 0; unsigned int j = 0; unsigned int destination = node_list->destination_id; - node_contact_t node_to_query; while (j < kademlia_alpha && i < node_list->size) { /* We need to have at most "kademlia_alpha" requests each time, according to the protocol */ /* Gets the node we want to send the query to */ - node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t); + node_contact_t node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t); if (node_to_query->id != node->id) { /* No need to query ourselves */ send_find_node(node, node_to_query->id, destination); j++; diff --git a/include/xbt/str.h b/include/xbt/str.h index 0f10bef8d0..c89cf9825c 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -55,11 +55,10 @@ static inline unsigned int xbt_str_hash_ext(const char *str, int str_len) { #ifdef XBT_DJB2_HASH_FUNCTION /* fast implementation of djb2 algorithm */ - int c; unsigned int hash = 5381; while (str_len--) { - c = *str++; + int c = *str++; hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ } # elif defined(XBT_FNV_HASH_FUNCTION) -- 2.20.1