From: Arnaud Giersch Date: Wed, 8 Nov 2017 15:58:43 +0000 (+0100) Subject: Avoid using memset to initialize structs. X-Git-Tag: v3.18~242^2~69 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8164c2d758134b0e83cded911ddd43ce07dc8ead?hp=ef990547781931de315e21501eaafa920d0687d6 Avoid using memset to initialize structs. --- diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index 6f45328304..471e322640 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -140,8 +140,7 @@ int console_add_host___link(lua_State *L) { } int console_add_host(lua_State *L) { - s_sg_platf_host_cbarg_t host; - memset(&host,0,sizeof(host)); + s_sg_platf_host_cbarg_t host{}; int type; // we get values from the table passed as argument @@ -303,8 +302,7 @@ int console_add_router(lua_State* L) { int console_add_route(lua_State *L) { XBT_DEBUG("Adding route"); - s_sg_platf_route_cbarg_t route; - memset(&route,0,sizeof(route)); + s_sg_platf_route_cbarg_t route{}; int type; lua_ensure(lua_istable(L, -1), "Bad Arguments to add a route. Should be a table with named arguments"); @@ -377,8 +375,7 @@ int console_add_route(lua_State *L) { } int console_add_ASroute(lua_State *L) { - s_sg_platf_route_cbarg_t ASroute; - memset(&ASroute,0,sizeof(ASroute)); + s_sg_platf_route_cbarg_t ASroute{}; lua_pushstring(L, "src"); lua_gettable(L, -2); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index a9e952e08e..9609323bf8 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -315,8 +315,7 @@ bool NetZoneImpl::getBypassRoute(routing::NetPoint* src, routing::NetPoint* dst, void NetZoneImpl::getGlobalRoute(routing::NetPoint* src, routing::NetPoint* dst, /* OUT */ std::vector* links, double* latency) { - s_sg_platf_route_cbarg_t route; - memset(&route, 0, sizeof(route)); + s_sg_platf_route_cbarg_t route{}; XBT_DEBUG("Resolve route from '%s' to '%s'", src->getCname(), dst->getCname()); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index ba6cbec0ed..1d6175c820 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -113,8 +113,7 @@ msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int coreAmount, int rams /* For the moment, intensity_rate is the percentage against the migration bandwidth */ msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount); - s_vm_params_t params; - memset(¶ms, 0, sizeof(params)); + s_vm_params_t params{}; params.ramsize = static_cast(ramsize) * 1024 * 1024; params.devsize = 0; params.skip_stage2 = 0; diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 3093fc596a..eecc1c70e0 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -117,8 +117,7 @@ simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const char *name) void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments, double process_start_time, double process_kill_time) { - s_sg_platf_process_cbarg_t process; - memset(&process,0,sizeof(process)); + s_sg_platf_process_cbarg_t process{}; sg_host_t host = sg_host_by_name(process_host); if (not host) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index ee0542ce8e..a853c3d89f 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -194,8 +194,7 @@ void sg_platf_new_cluster(ClusterCreationArgs* cluster) XBT_DEBUG("", host_id.c_str(), cluster->speeds.front()); - s_sg_platf_host_cbarg_t host; - memset(&host, 0, sizeof(host)); + s_sg_platf_host_cbarg_t host{}; host.id = host_id.c_str(); if ((cluster->properties != nullptr) && (not cluster->properties->empty())) { host.properties = new std::map; @@ -315,8 +314,7 @@ void sg_platf_new_cabinet(CabinetCreationArgs* cabinet) { for (int const& radical : *cabinet->radicals) { std::string hostname = cabinet->prefix + std::to_string(radical) + cabinet->suffix; - s_sg_platf_host_cbarg_t host; - memset(&host, 0, sizeof(host)); + s_sg_platf_host_cbarg_t host{}; host.pstate = 0; host.core_amount = 1; host.id = hostname.c_str(); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 6730a350ff..e370d13152 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -426,8 +426,7 @@ void STag_surfxml_prop() } void ETag_surfxml_host() { - s_sg_platf_host_cbarg_t host; - memset(&host,0,sizeof(host)); + s_sg_platf_host_cbarg_t host{}; host.properties = current_property_set; current_property_set = nullptr; @@ -693,8 +692,7 @@ void STag_surfxml_bypassZoneRoute(){ } void ETag_surfxml_route(){ - s_sg_platf_route_cbarg_t route; - memset(&route,0,sizeof(route)); + s_sg_platf_route_cbarg_t route{}; route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag @@ -722,8 +720,7 @@ void ETag_surfxml_ASroute() } void ETag_surfxml_zoneRoute() { - s_sg_platf_route_cbarg_t ASroute; - memset(&ASroute,0,sizeof(ASroute)); + s_sg_platf_route_cbarg_t ASroute{}; ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag @@ -754,8 +751,7 @@ void ETag_surfxml_zoneRoute() } void ETag_surfxml_bypassRoute(){ - s_sg_platf_route_cbarg_t route; - memset(&route,0,sizeof(route)); + s_sg_platf_route_cbarg_t route{}; route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag @@ -782,8 +778,7 @@ void ETag_surfxml_bypassASroute() } void ETag_surfxml_bypassZoneRoute() { - s_sg_platf_route_cbarg_t ASroute; - memset(&ASroute,0,sizeof(ASroute)); + s_sg_platf_route_cbarg_t ASroute{}; ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src); ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst); @@ -929,8 +924,7 @@ void ETag_surfxml_process() void ETag_surfxml_actor() { - s_sg_platf_process_cbarg_t actor; - memset(&actor,0,sizeof(actor)); + s_sg_platf_process_cbarg_t actor{}; actor.properties = current_property_set; current_property_set = nullptr;