From: Frederic Suter Date: Tue, 20 Jun 2017 08:12:10 +0000 (+0200) Subject: a few codacy treats X-Git-Tag: v3.16~24 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/da6b18121779fcbadaef944c4bafe2d9451fe5be a few codacy treats --- diff --git a/examples/msg/actions-storage/actions-storage.c b/examples/msg/actions-storage/actions-storage.c index a4e0becd77..815b7ce0d7 100644 --- a/examples/msg/actions-storage/actions-storage.c +++ b/examples/msg/actions-storage/actions-storage.c @@ -28,11 +28,10 @@ static void log_action(const char *const *action, double date) static msg_file_t get_file_descriptor(const char *file_name){ char full_name[1024]; - msg_file_t file = NULL; snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name); - file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name); + msg_file_t file = (msg_file_t)xbt_dict_get_or_null(opened_files, full_name); return file; } diff --git a/examples/msg/app-token-ring/app-token-ring.c b/examples/msg/app-token-ring/app-token-ring.c index 3a6c0196c6..1f046a77ae 100644 --- a/examples/msg/app-token-ring/app-token-ring.c +++ b/examples/msg/app-token-ring/app-token-ring.c @@ -11,13 +11,13 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_token_ring, "Messages specific for this msg static int relay_runner(int argc, char *argv[]) { xbt_assert(argc==0, "The relay_runner function does not accept any parameter from the XML deployment file"); - unsigned int task_comm_size = 1000000; /* The token is 1MB long*/ int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Any process of this example must have a numerical name, not %s"); char mailbox[256]; if (rank == 0) { /* The root process (rank 0) first sends the token then waits to receive it back */ snprintf(mailbox,255, "%d", rank+1); + unsigned int task_comm_size = 1000000; /* The token is 1MB long*/ msg_task_t task = MSG_task_create("Token", 0, task_comm_size, NULL); XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name,mailbox); MSG_task_send(task, mailbox); diff --git a/examples/msg/dht-chord/dht-chord.c b/examples/msg/dht-chord/dht-chord.c index 88096d24ba..1cb3654984 100644 --- a/examples/msg/dht-chord/dht-chord.c +++ b/examples/msg/dht-chord/dht-chord.c @@ -367,7 +367,6 @@ int find_successor(node_t node, int id) int remote_find_successor(node_t node, int ask_to, int id) { int successor = -1; - int stop = 0; char mailbox[MAILBOX_NAME_SIZE]; get_mailbox(ask_to, mailbox); task_data_t req_data = xbt_new0(s_task_data_t, 1); @@ -385,6 +384,7 @@ int remote_find_successor(node_t node, int ask_to, int id) XBT_DEBUG("Failed to send the 'Find Successor' request (task %p) to %d for id %d", task_sent, ask_to, id); task_free(task_sent); } else { + int stop = 0; // receive the answer XBT_DEBUG("Sent a 'Find Successor' request (task %p) to %d for key %d, waiting for the answer", task_sent, ask_to, id); diff --git a/examples/msg/io-storage/io-storage.c b/examples/msg/io-storage/io-storage.c index c4731aeafe..298e6e6501 100644 --- a/examples/msg/io-storage/io-storage.c +++ b/examples/msg/io-storage/io-storage.c @@ -93,8 +93,7 @@ static int host(int argc, char *argv[]){ /* - Finally dump disks contents */ XBT_INFO("*** Dump content of %s ***",MSG_host_get_name(MSG_host_self())); - xbt_dict_t contents = NULL; - contents = MSG_host_get_storage_content(MSG_host_self()); // contents is a dict of dicts + xbt_dict_t contents = MSG_host_get_storage_content(MSG_host_self()); // contents is a dict of dicts xbt_dict_cursor_t curs; xbt_dict_cursor_t curs2 = NULL; char* mountname; diff --git a/examples/s4u/dht-chord/s4u_dht-chord.hpp b/examples/s4u/dht-chord/s4u_dht-chord.hpp index a415bf9bd3..9d764383c7 100644 --- a/examples/s4u/dht-chord/s4u_dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u_dht-chord.hpp @@ -63,9 +63,8 @@ public: int answer_id = -1; // answer (used by some types of messages) simgrid::s4u::MailboxPtr answer_to; // mailbox to send an answer to (if any) - explicit ChordMessage(e_message_type_t type) : type(type) + explicit ChordMessage(e_message_type_t type) : type(type), issuer_host_name(simgrid::s4u::this_actor::host()->name()) { - issuer_host_name = simgrid::s4u::this_actor::host()->name(); } ~ChordMessage() = default; diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index abb1bacc0e..b73264969a 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -90,10 +90,7 @@ static void __JAVA_host_priv_free(void *host) JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) { - int index; int argc = 0; - jstring jval; - const char *tmp; XBT_LOG_CONNECT(java); XBT_LOG_CONNECT(jtrace); @@ -115,9 +112,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j char** argv = new char*[argc + 1]; argv[0] = xbt_strdup("java"); - for (index = 0; index < argc - 1; index++) { - jval = (jstring) env->GetObjectArrayElement(jargs, index); - tmp = env->GetStringUTFChars(jval, 0); + for (int index = 0; index < argc - 1; index++) { + jstring jval = (jstring)env->GetObjectArrayElement(jargs, index); + const char* tmp = env->GetStringUTFChars(jval, 0); argv[index + 1] = xbt_strdup(tmp); env->ReleaseStringUTFChars(jval, tmp); } @@ -127,7 +124,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(__JAVA_host_priv_free); - for (index = 0; index < argc - 1; index++) { + for (int index = 0; index < argc - 1; index++) { env->SetObjectArrayElement(jargs, index, (jstring)env->NewStringUTF(argv[index + 1])); free(argv[index]); } diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 39dab91268..dca285d1eb 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -33,22 +33,17 @@ TorusZone::TorusZone(NetZone* father, const char* name) : ClusterZone(father, na void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) { - /* - * Create all links that exist in the torus. - * Each rank creates @a dimensions-1 links - */ - int neighbor_rank_id = 0; // The other node the link connects - int current_dimension = 0; // which dimension are we currently in? - // we need to iterate over all dimensions - // and create all links there + /* Create all links that exist in the torus. Each rank creates @a dimensions-1 links */ int dim_product = 1; // Needed to calculate the next neighbor_id - for (unsigned int j = 0; j < dimensions_.size(); j++) { + for (unsigned int j = 0; j < dimensions_.size(); j++) { LinkCreationArgs link; - current_dimension = dimensions_.at(j); - neighbor_rank_id = ((static_cast(rank) / dim_product) % current_dimension == current_dimension - 1) - ? rank - (current_dimension - 1) * dim_product - : rank + dim_product; + int current_dimension = dimensions_.at(j); // which dimension are we currently in? + // we need to iterate over all dimensions and create all links there + // The other node the link connects + int neighbor_rank_id = ((static_cast(rank) / dim_product) % current_dimension == current_dimension - 1) + ? rank - (current_dimension - 1) * dim_product + : rank + dim_product; // name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case) char* link_id = bprintf("%s_link_from_%i_to_%i", cluster->id, id, neighbor_rank_id); link.id = link_id; diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 8d59a21358..5f948a5551 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -274,7 +274,7 @@ static int migration_rx_fun(int argc, char *argv[]) XBT_DEBUG("mig: rx_start"); // The structure has been created in the do_migration function and should only be freed in the same place ;) - struct migration_session *ms = (migration_session *) MSG_process_get_data(MSG_process_self()); + struct migration_session* ms = static_cast(MSG_process_get_data(MSG_process_self())); bool received_finalize = false; diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index f0b33205bd..48b9c1e4da 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -1,5 +1,5 @@ /* Copyright (c) 2014-2015. The SimGrid Team. - * All rights reserved. */ +*All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -125,7 +125,6 @@ namespace simgrid { } void NetworkIBModel::computeIBfactors(IBNode *root) { - double penalized_bw=0.0; double num_comm_out = (double) root->ActiveCommsUp.size(); double max_penalty_out=0.0; //first, compute all outbound penalties to get their max @@ -159,7 +158,7 @@ namespace simgrid { if((*it)->init_rate==-1) (*it)->init_rate= rate_before_update; - penalized_bw = num_comm_out ? (*it)->init_rate / penalty : (*it)->init_rate; + double penalized_bw = num_comm_out ? (*it)->init_rate / penalty : (*it)->init_rate; if (not double_equals(penalized_bw, rate_before_update, sg_surf_precision)) { XBT_DEBUG("%d->%d action %p penalty updated : bw now %f, before %f , initial rate %f", root->id,(*it)->destination->id,(*it)->action,penalized_bw, (*it)->action->getBound(), (*it)->init_rate ); diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index f04b8635d7..d8d37251ec 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -102,24 +102,19 @@ static void initialize(xbt_mheap_t mdp) * into the heap info table as necessary. */ static void *register_morecore(struct mdesc *mdp, size_t size) { - int i; - void *result; - malloc_info *newinfo, *oldinfo; - size_t newsize; - - result = align(mdp, size); // Never returns NULL + void* result = align(mdp, size); // Never returns NULL /* Check if we need to grow the info table (in a multiplicative manner) */ if ((size_t) BLOCK((char *) result + size) > mdp->heapsize) { int it; - newsize = mdp->heapsize; + size_t newsize = mdp->heapsize; while ((size_t) BLOCK((char *) result + size) > newsize) newsize *= 2; /* Copy old info into new location */ - oldinfo = mdp->heapinfo; - newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info)); + malloc_info* oldinfo = mdp->heapinfo; + malloc_info* newinfo = (malloc_info*)align(mdp, newsize * sizeof(malloc_info)); memcpy(newinfo, oldinfo, mdp->heapsize * sizeof(malloc_info)); /* Initialise the new blockinfo : */ @@ -129,14 +124,12 @@ static void *register_morecore(struct mdesc *mdp, size_t size) /* Update the swag of busy blocks containing free fragments by applying the offset to all swag_hooks. Yeah. My hand is right in the fan and I still type */ size_t offset=((char*)newinfo)-((char*)oldinfo); - for (i=1/*first element of heapinfo describes the mdesc area*/; - iheaplimit; - i++) { + for (int i = 1 /*first element of heapinfo describes the mdesc area*/; i < mdp->heaplimit; i++) { update_hook(newinfo[i].freehook.next,offset); update_hook(newinfo[i].freehook.prev,offset); } // also update the starting points of the swag - for (i=0;ifraghead[i].head,offset); update_hook(mdp->fraghead[i].tail,offset); } @@ -176,7 +169,9 @@ void *mmalloc(xbt_mheap_t mdp, size_t size) { void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size) { void *result; - size_t block, blocks, lastblocks, start; + size_t block; + size_t blocks; + size_t lastblocks size_t start; size_t i; size_t log; int it;