From 5b78fc9f704153c9832230883dfd847f2bcf791d Mon Sep 17 00:00:00 2001 From: agiersch Date: Tue, 22 Feb 2011 13:19:19 +0000 Subject: [PATCH] Replace a combination of malloc+strcpy by xbt_strdup. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9681 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/bindings/lua/lua_console.c | 3 +-- src/instr/jedule/jedule_events.c | 6 ++---- src/instr/jedule/jedule_platform.c | 3 +-- src/surf/network.c | 6 ++---- src/surf/network_im.c | 6 ++---- tools/gras/windows_stub_generator.c | 15 ++++----------- 6 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/bindings/lua/lua_console.c b/src/bindings/lua/lua_console.c index abcc05e25e..da12ba5a04 100644 --- a/src/bindings/lua/lua_console.c +++ b/src/bindings/lua/lua_console.c @@ -411,8 +411,7 @@ static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_tab route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref); - char *tmp_links = malloc(sizeof(char)*strlen(links)+1);//use xbt - strcpy(tmp_links,links); + char *tmp_links = xbt_strdup(links); link_id = strtok(tmp_links,","); //tmp_link = strtok((char*)links,","); while(link_id != NULL) { diff --git a/src/instr/jedule/jedule_events.c b/src/instr/jedule/jedule_events.c index 5075f4dbb1..bab0e0c7c6 100644 --- a/src/instr/jedule/jedule_events.c +++ b/src/instr/jedule/jedule_events.c @@ -54,14 +54,12 @@ void create_jed_event(jed_event_t *event, char *name, double start_time, double end_time, const char *type) { *event = (jed_event_t) calloc(1, sizeof(s_jed_event_t)); - (*event)->name = (char*) calloc(strlen(name) + 1, sizeof(char)); - strcpy((*event)->name, name); + (*event)->name = xbt_strdup(name); (*event)->start_time = start_time; (*event)->end_time = end_time; - (*event)->type = (char*) calloc(strlen(type) + 1, sizeof(char)); - strcpy((*event)->type, type); + (*event)->type = xbt_strdup(type); (*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), NULL); (*event)->characteristics_list = xbt_dynar_new(sizeof(char*), NULL); diff --git a/src/instr/jedule/jedule_platform.c b/src/instr/jedule/jedule_platform.c index 04d31b1277..6ffefdaea5 100644 --- a/src/instr/jedule/jedule_platform.c +++ b/src/instr/jedule/jedule_platform.c @@ -66,8 +66,7 @@ void jed_simgrid_create_container(jed_simgrid_container_t *container, char *name xbt_assert( name != NULL ); *container = (jed_simgrid_container_t)calloc(1,sizeof(s_jed_simgrid_container_t)); - (*container)->name = (char*)calloc((strlen(name)+1), sizeof(char)); - strcpy((*container)->name, name); + (*container)->name = xbt_strdup(name); (*container)->is_lowest = 0; (*container)->container_children = xbt_dynar_new(sizeof(jed_simgrid_container_t), NULL); (*container)->parent = NULL; diff --git a/src/surf/network.c b/src/surf/network.c index 7a75d8b507..3864fd918e 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -733,11 +733,9 @@ static surf_action_t net_communicate(const char *src_name, /* LARGE PLATFORMS HACK: expand also with src->link and dst->link */ #ifdef HAVE_TRACING - action->src_name = xbt_new(char, strlen(src_name) + 1); - strncpy(action->src_name, src_name, strlen(src_name) + 1); + action->src_name = xbt_strdup(src_name); - action->dst_name = xbt_new(char, strlen(dst_name) + 1); - strncpy(action->dst_name, dst_name, strlen(dst_name) + 1); + action->dst_name = xbt_strdup(dst_name); #endif xbt_dynar_free(&route); diff --git a/src/surf/network_im.c b/src/surf/network_im.c index 86e53b4e91..643a76e0d6 100644 --- a/src/surf/network_im.c +++ b/src/surf/network_im.c @@ -783,11 +783,9 @@ static surf_action_t im_net_communicate(const char *src_name, /* LARGE PLATFORMS HACK: expand also with src->link and dst->link */ #ifdef HAVE_TRACING - action->src_name = xbt_new(char, strlen(src_name) + 1); - strncpy(action->src_name, src_name, strlen(src_name) + 1); + action->src_name = xbt_strdup(src_name); - action->dst_name = xbt_new(char, strlen(dst_name) + 1); - strncpy(action->dst_name, dst_name, strlen(dst_name) + 1); + action->dst_name = xbt_strdup(dst_name); #endif xbt_dynar_free(&route); diff --git a/tools/gras/windows_stub_generator.c b/tools/gras/windows_stub_generator.c index 585ba12e61..77a9fe9578 100644 --- a/tools/gras/windows_stub_generator.c +++ b/tools/gras/windows_stub_generator.c @@ -660,9 +660,7 @@ void generate_borland_simulation_project(const char *name) GetCurrentDirectory(MAX_PATH, buffer); - borland_project.src_dir = xbt_new0(char, strlen(buffer) + 1); - - strcpy(borland_project.src_dir, buffer); + borland_project.src_dir = xbt_strdup(buffer); borland_project.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2); @@ -717,9 +715,7 @@ void generate_borland_real_life_project(const char *name) GetCurrentDirectory(MAX_PATH, buffer); - borland_project.src_dir = xbt_new0(char, strlen(buffer) + 1); - - strcpy(borland_project.src_dir, buffer); + borland_project.src_dir = xbt_strdup(buffer); borland_project.bin_dir = xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1); @@ -838,8 +834,7 @@ int generate_simulation_dsp_file(const char *name) GetEnvironmentVariable("LIB_SIMGRID_PATH", dsp.lib_dir, MAX_PATH); GetCurrentDirectory(MAX_PATH, buffer); - dsp.src_dir = xbt_new0(char, strlen(buffer) + 1); - strcpy(dsp.src_dir, buffer); + dsp.src_dir = xbt_strdup(buffer); dsp.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2); sprintf(dsp.name, "%s_simulator", name); @@ -871,9 +866,7 @@ int generate_real_live_dsp_file(const char *name) GetCurrentDirectory(MAX_PATH, buffer); - dsp.src_dir = xbt_new0(char, strlen(buffer) + 1); - - strcpy(dsp.src_dir, buffer); + dsp.src_dir = xbt_strdup(buffer); xbt_dict_foreach(process_function_set, cursor, key, data) { -- 2.20.1