From: Arnaud Giersch Date: Wed, 16 Mar 2022 22:36:27 +0000 (+0100) Subject: Fix spurious compilation warning. X-Git-Tag: v3.31~68 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9075ee30418590d5cfd216f7ae86e77dd7ebf936?hp=82ba4833dfc9c17a30b3639b5973bcd850a019c3 Fix spurious compilation warning. warning: ‘main’ may be used uninitialized in this function. --- diff --git a/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp b/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp index 183179a5f1..b6334cf3b3 100644 --- a/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp +++ b/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp @@ -102,25 +102,21 @@ int main(int argc, char* argv[]) sg4::Engine e(&argc, argv); auto* rootzone = sg4::create_full_zone("root"); - sg4::Host* main; // First host created, where the master will stay std::vector worker_hosts; xbt_assert(cfg_host_count > 2, "You need at least 2 workers (i.e., 3 hosts) or the master will be auto-killed when " "the only worker gets killed."); - for (int i = 0; i < cfg_host_count; i++) { + sg4::Host* master_host = rootzone->create_host("lilibeth 0", 1e9); // Host where the master will stay + for (int i = 1; i < cfg_host_count; i++) { auto hostname = std::string("lilibeth ") + std::to_string(i); auto* host = rootzone->create_host(hostname, 1e9); - if (i == 0) { - main = host; - } else { - sg4::LinkInRoute link(rootzone->create_link(hostname, "1MBps")->set_latency("24us")->seal()); - rootzone->add_route(main->get_netpoint(), host->get_netpoint(), nullptr, nullptr, {link}, true); - worker_hosts.push_back(host); - } + sg4::LinkInRoute link(rootzone->create_link(hostname, "1MBps")->set_latency("24us")->seal()); + rootzone->add_route(master_host->get_netpoint(), host->get_netpoint(), nullptr, nullptr, {link}, true); + worker_hosts.push_back(host); } rootzone->seal(); - sg4::Actor::create("master", main, master)->daemonize()->set_auto_restart(true); + sg4::Actor::create("master", master_host, master)->daemonize()->set_auto_restart(true); int id = 0; for (auto* h : worker_hosts) { sg4::Actor::create("worker", h, worker, id)->set_auto_restart(true);