From: navarrop Date: Fri, 4 Jun 2010 16:04:25 +0000 (+0000) Subject: Do not declare variable in the middle of nowhere! X-Git-Tag: v3_5~982 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/87bf71ddfe2611ffedaabe6c3a9030957ae4a080 Do not declare variable in the middle of nowhere! git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7826 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 2f1158ebaf..311917683f 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -609,14 +609,14 @@ gras_datadesc_type_t gras_datadesc_array_dyn(const char *name, gras_datadesc_type_t gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) { - + int cpt=0; gras_datadesc_type_t res,ddt2; char *name = (char *) xbt_malloc(strlen(element_type->name) + 4); sprintf(name, "%s[]", element_type->name); /* Make sure we are not trying to redefine a ddt with the same name */ ddt2 = gras_datadesc_by_name_or_null(name); - int cpt=0; + while (ddt2) { free(name); name=bprintf("%s[]_%d",element_type->name,cpt++); diff --git a/src/msg/msg_actions.c b/src/msg/msg_actions.c index 05476ffc8e..c4da3ff3ab 100644 --- a/src/msg/msg_actions.c +++ b/src/msg/msg_actions.c @@ -49,6 +49,12 @@ void MSG_action_unregister(const char *action_name) static int MSG_action_runner(int argc, char *argv[]) { xbt_dynar_t evt=NULL; + char *line = NULL; + size_t line_len = 0; + FILE *fp = NULL; + char *comment = NULL; + char *evtname = NULL; + ssize_t read; if (action_fp) { // A unique trace file while ((evt = action_get_action(argv[0]))) { @@ -63,16 +69,13 @@ static int MSG_action_runner(int argc, char *argv[]) { "and no process-wide trace file provided in deployment file. Aborting.",argv[0] ); - char *line = NULL; - size_t line_len = 0; - FILE *fp = fopen(argv[1], "r"); + fp = fopen(argv[1], "r"); xbt_assert2(fp != NULL, "Cannot open %s: %s", argv[1], strerror(errno)); - ssize_t read; // Read lines and execute them until I reach the end of file while ((read = getline(&line, &line_len, fp)) != -1) { // cleanup and split the string I just read - char *comment = strchr(line, '#'); + comment = strchr(line, '#'); if (comment != NULL) *comment = '\0'; xbt_str_trim(line, NULL); @@ -80,7 +83,7 @@ static int MSG_action_runner(int argc, char *argv[]) { continue; evt = xbt_str_split_quoted(line); - char *evtname = xbt_dynar_get_as(evt, 0, char *); + evtname = xbt_dynar_get_as(evt, 0, char *); if (!strcmp(argv[0],evtname)) { msg_action_fun function = xbt_dict_get(action_funs, xbt_dynar_get_as(evt, 1, char *)); @@ -111,7 +114,7 @@ void _MSG_action_exit() { static xbt_dynar_t action_get_action(char *name) { ssize_t read; xbt_dynar_t evt=NULL; - + char *evtname = NULL; xbt_dynar_t myqueue = xbt_dict_get_or_null(action_queues,name); if (myqueue==NULL || xbt_dynar_length(myqueue)==0) { // nothing stored for me. Read the file further @@ -133,7 +136,7 @@ static xbt_dynar_t action_get_action(char *name) { evt = xbt_str_split_quoted(action_line); // if it's for me, I'm done - char *evtname = xbt_dynar_get_as(evt, 0, char *); + evtname = xbt_dynar_get_as(evt, 0, char *); if (!strcmp(name,evtname)) { return evt; } else { @@ -173,6 +176,9 @@ static xbt_dynar_t action_get_action(char *name) { MSG_error_t MSG_action_trace_run(char *path) { MSG_error_t res; + char *name; + xbt_dynar_t todo; + xbt_dict_cursor_t cursor; if (path) { action_fp = fopen(path, "r"); @@ -182,9 +188,7 @@ MSG_error_t MSG_action_trace_run(char *path) if (xbt_dict_size(action_queues)) { WARN0("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); - xbt_dict_cursor_t cursor; - char *name; - xbt_dynar_t todo; + xbt_dict_foreach(action_queues,cursor,name,todo) { WARN2("Still %lu actions for %s",xbt_dynar_length(todo),name); diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index 54ae08af2a..5bc26811a1 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -173,10 +173,10 @@ void SIMIX_function_register_default(xbt_main_func_t code) */ xbt_main_func_t SIMIX_get_registered_function(const char *name) { + xbt_main_func_t res = NULL; xbt_assert0(simix_global, "SIMIX_global_init has to be called before SIMIX_get_registered_function."); - xbt_main_func_t res = - xbt_dict_get_or_null(simix_global->registered_functions, name); + res = xbt_dict_get_or_null(simix_global->registered_functions, name); return res ? res : default_function; } diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index f3096b92f5..f9180c3d1d 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -421,9 +421,11 @@ void SIMIX_process_resume(smx_process_t process) void SIMIX_process_change_host(smx_process_t process, char *source, char *dest) { + smx_host_t h1 = NULL; + smx_host_t h2 = NULL; xbt_assert0((process != NULL), "Invalid parameters"); - smx_host_t h1 = SIMIX_host_get_by_name(source); - smx_host_t h2 = SIMIX_host_get_by_name(dest); + h1 = SIMIX_host_get_by_name(source); + h2 = SIMIX_host_get_by_name(dest); process->smx_host = h2; xbt_swag_remove(process, h1->process_list); xbt_swag_insert(process, h2->process_list); diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index 1aaacc5808..5de5313823 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -349,12 +349,11 @@ smx_sem_t SIMIX_sem_init(int capacity) { } /** @brief Destroys a semaphore */ void SIMIX_sem_destroy(smx_sem_t sem) { + smx_action_t action = NULL; DEBUG1("Destroy semaphore %p", sem); if (sem == NULL) return; - smx_action_t action = NULL; - xbt_assert0(xbt_swag_size(sem->sleeping) == 0, "Cannot destroy semaphore since someone is still using it"); xbt_swag_free(sem->sleeping); diff --git a/src/surf/network.c b/src/surf/network.c index de86cc00a6..61952158a8 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -381,6 +381,9 @@ static void net_update_resource_state(void *id, static surf_action_t net_communicate(const char *src_name, const char *dst_name, int src, int dst, double size, double rate) { + unsigned int i; + link_CM02_t link; + int failed = 0; surf_action_network_CM02_t action = NULL; /* LARGE PLATFORMS HACK: Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node @@ -388,7 +391,6 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, xbt_dynar_t route = used_routing->get_route(src, dst); /* LARGE PLATFORMS HACK: total_route_size = route_size + src->link_nb + dst->nb */ - unsigned int i; XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); /* LARGE PLATFORMS HACK: @@ -397,8 +399,6 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, "You're trying to send data from %s to %s but there is no connection between these two hosts.", src_name, dst_name); - link_CM02_t link; - int failed = 0; xbt_dynar_foreach(route, i, link) { if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) { failed = 1; diff --git a/src/surf/network_vivaldi.c b/src/surf/network_vivaldi.c index 8be7582331..74afcc47aa 100644 --- a/src/surf/network_vivaldi.c +++ b/src/surf/network_vivaldi.c @@ -128,15 +128,12 @@ static void netviva_update_resource_state(void *id, static surf_action_t netviva_communicate(const char *src_name, const char *dst_name, int src, int dst, double size, double rate) { + surf_action_network_Vivaldi_t action = NULL; netviva_coords_t c1,c2; c1 = xbt_dict_get(coords,src_name); c2 = xbt_dict_get(coords,dst_name); - surf_action_network_Vivaldi_t action = NULL; - - action = - surf_action_new(sizeof(s_surf_action_network_Vivaldi_t), size, - surf_network_model, 0); + action = surf_action_new(sizeof(s_surf_action_network_Vivaldi_t), size,surf_network_model, 0); action->suspended = 0; diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 455a5a92e3..7f5e6fb3bb 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -164,17 +164,16 @@ static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){ /* create the config set, register what should be and parse the command line*/ void surf_config_init(int *argc, char **argv) { - - /* Create the configuration support */ - if (_surf_init_status == 0) { /* Only create stuff if not already inited */ - _surf_init_status = 1; - char *description = xbt_malloc(1024), *p = description; char *default_value; double double_default_value; int default_value_int; int i; + /* Create the configuration support */ + if (_surf_init_status == 0) { /* Only create stuff if not already inited */ + _surf_init_status = 1; + sprintf(description, "The model to use for the CPU. Possible values: "); p = description; while (*(++p) != '\0'); @@ -303,13 +302,14 @@ void surf_config_models_setup(const char *platform_file) { char *workstation_model_name; int workstation_id = -1; - + char *network_model_name = NULL; + char *cpu_model_name = NULL; surf_timer_model_init(platform_file); workstation_model_name = xbt_cfg_get_string(_surf_cfg_set, "workstation/model"); - char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model"); - char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model"); + network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model"); + cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model"); if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01")) && !strcmp(workstation_model_name, "CLM03")){ diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index fef83e49b4..bdfe1b3402 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -172,7 +172,9 @@ static void routing_full_parse_Scluster(void) char *cluster_bb_bw = A_surfxml_cluster_bb_bw; char *cluster_bb_lat = A_surfxml_cluster_bb_lat; char *backbone_name; - + unsigned int it1,it2; + char *name1,*name2; + xbt_dynar_t names = NULL; surfxml_bufferstack_push(1); /* Make set a set to parse the prefix/suffix/radical into a neat list of names */ @@ -186,10 +188,8 @@ static void routing_full_parse_Scluster(void) SURFXML_START_TAG(set); SURFXML_END_TAG(set); - xbt_dynar_t names = xbt_dict_get(set_list,cluster_id); + names = xbt_dict_get(set_list,cluster_id); - unsigned int it1,it2; - char *name1,*name2; xbt_dynar_foreach(names,it1,name1) { /* create the host */ routing_full_parse_change_cpu_data(name1, cluster_power, "1.0", "", ""); @@ -496,8 +496,10 @@ static void routing_floyd_parse_end(void) { xbt_dynar_t links, keys; unsigned int i,j; - + unsigned int a,b,c; int host_count = routing->generic_routing.host_count; + char * link_name = NULL; + void * link = NULL; /* Create Cost, Predecessor and Link tables */ cost_table = xbt_new0(double, host_count * host_count); //link cost from host to host @@ -527,8 +529,9 @@ static void routing_floyd_parse_end(void) { src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links)); xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id); - char * link_name = xbt_dynar_getfirst_as(links, char*); - void * link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + link_name = xbt_dynar_getfirst_as(links, char*); + link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + if (link) link_list = link; else @@ -553,7 +556,7 @@ static void routing_floyd_parse_end(void) { //Calculate path costs - unsigned int a,b,c; + for(c=0;cid = id; data->graph_id = graph_id; - xbt_node_t node = xbt_graph_new_node(routing->route_graph, data); + node = xbt_graph_new_node(routing->route_graph, data); - graph_node_map_element_t elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element)); + elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element)); elm->node = node; xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free); @@ -789,7 +795,11 @@ static void routing_dijkstra_parse_end(void) { char *key, *data, *end; const char *sep = "#"; xbt_dynar_t links, keys; - + char* link_name = NULL; + void* link = NULL; + xbt_node_t node = NULL; + unsigned int cursor2; + xbt_dynar_t nodes = NULL; /* Create the topology graph */ routing->route_graph = xbt_graph_new_graph(1, NULL); routing->graph_node_map = xbt_dict_new(); @@ -813,8 +823,8 @@ static void routing_dijkstra_parse_end(void) { xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id); - char* link_name = xbt_dynar_getfirst_as(links, char*); - void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + link_name = xbt_dynar_getfirst_as(links, char*); + link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); if (link) route_new_dijkstra(src_id,dst_id,link); else @@ -826,10 +836,8 @@ static void routing_dijkstra_parse_end(void) { add_loopback_dijkstra(); /* initialize graph indexes in nodes after graph has been built */ - xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); + nodes = xbt_graph_get_nodes(routing->route_graph); - xbt_node_t node = NULL; - unsigned int cursor2; xbt_dynar_foreach(nodes, cursor2, node) { graph_node_data_t data = xbt_graph_node_get_data(node); data->graph_id = cursor2; @@ -844,17 +852,22 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { routing_dijkstra_t routing = (routing_dijkstra_t) used_routing; int * pred_arr = NULL; - + int src_node_id = 0; + int dst_node_id = 0; + int * nodeid = NULL; + int v; + int size = 0; + void * link = NULL; + route_cache_element_t elm = NULL; xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); /*Use the graph_node id mapping set to quickly find the nodes */ graph_node_map_element_t src_elm = graph_node_map_search(src_id); graph_node_map_element_t dst_elm = graph_node_map_search(dst_id); xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", src_id, dst_id); - int src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id; - int dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id; + src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id; + dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id; - route_cache_element_t elm = NULL; if(routing->cached) { /*check if there is a cached predecessor list avail */ elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int)); @@ -883,7 +896,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { pred_arr[i] = 0; //initialize priority queue - int * nodeid = xbt_new0(int, 1); + nodeid = xbt_new0(int, 1); *nodeid = i; xbt_heap_push(pqueue, nodeid, cost_arr[i]); @@ -906,7 +919,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { pred_arr[u_id] = *v_id; cost_arr[u_id] = cost_v_u + cost_arr[*v_id]; - int * nodeid = xbt_new0(int, 1); + nodeid = xbt_new0(int, 1); *nodeid = u_id; xbt_heap_push(pqueue, nodeid, cost_arr[u_id]); } @@ -924,8 +937,6 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { //compose route path with links xbt_dynar_reset(routing->last_route); - int v; - int size = 0; for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) { xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t); xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t); @@ -933,7 +944,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { xbt_assert2(edge != NULL, "no route between host %d and %d", src_id, dst_id); - void * link = xbt_graph_edge_get_data(edge); + link = xbt_graph_edge_get_data(edge); xbt_dynar_unshift(routing->last_route, &link); size++; } diff --git a/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index fba9362909..03827df497 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -100,6 +100,7 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, tmgr_trace_t tmgr_trace_new(const char *filename) { + char *tstr = NULL; FILE *f = NULL; tmgr_trace_t trace = NULL; @@ -118,7 +119,7 @@ tmgr_trace_t tmgr_trace_new(const char *filename) xbt_assert2(f!=NULL, "Cannot open file '%s' (path=%s)", filename, xbt_str_join(surf_path,":")); - char *tstr = xbt_str_from_file(f); + tstr = xbt_str_from_file(f); fclose(f); trace = tmgr_trace_new_from_string(filename, tstr, 0.); xbt_free(tstr); diff --git a/src/xbt/setset.c b/src/xbt/setset.c index a583713620..e01e105286 100644 --- a/src/xbt/setset.c +++ b/src/xbt/setset.c @@ -44,10 +44,10 @@ void xbt_setset_destroy(xbt_setset_t setset) void xbt_setset_elm_add(xbt_setset_t setset, void *obj) { xbt_setset_elm_entry_t new_entry = NULL; + xbt_setset_elm_entry_t first_elm = NULL; xbt_setset_elm_t e = (xbt_setset_elm_t)obj; xbt_assert0(e->ID == 0, "Adding element with non NULL ID"); - xbt_setset_elm_entry_t first_elm = - (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, 0); + first_elm = (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, 0); /* Before create a new elm entry check if there is one in the free elm list. */ /* If there is not free elm entries, then create a new one */ @@ -356,4 +356,4 @@ int bitcount(int v) v = v - ((v >> 1) & 0x55555555); // reuse input as temporary v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count -} \ No newline at end of file +} diff --git a/src/xbt/xbt_log_layout_simple.c b/src/xbt/xbt_log_layout_simple.c index 277ea18e6c..539469982d 100644 --- a/src/xbt/xbt_log_layout_simple.c +++ b/src/xbt/xbt_log_layout_simple.c @@ -73,7 +73,7 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l, xbt_log_appender_t app) { char *p; - + const char *procname=NULL; xbt_assert0(ev->priority >= 0, "Negative logging priority naturally forbidden"); xbt_assert1(ev->priority < sizeof(xbt_log_priority_names), @@ -85,7 +85,7 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l, check_overflow; /* Display the proc info if available */ - const char *procname=xbt_procname(); + procname=xbt_procname(); if (strlen(procname)) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%s:(%d) ", gras_os_myname(), procname, (*xbt_getpid) ());