Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the scope of some variables to please codacy
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 24 May 2017 00:13:58 +0000 (02:13 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 24 May 2017 00:13:58 +0000 (02:13 +0200)
examples/msg/dht-kademlia/answer.c
examples/msg/dht-kademlia/dht-kademlia.c
include/xbt/str.h

index 1cd48a0..6fb5f75 100644 (file)
@@ -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++;
   }
index 463fd01..439ad0f 100644 (file)
@@ -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++;
index 0f10bef..c89cf98 100644 (file)
@@ -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)