From 16925d4563b0fd3a17dc7c05f91c9439e6fb2462 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 23 Dec 2019 21:56:43 +0100 Subject: [PATCH] [sonar] Constify pointer and reference local variables in teshsuite/. --- teshsuite/mc/dwarf/dwarf.cpp | 4 ++-- teshsuite/mc/mutex-handling/mutex-handling.c | 2 +- teshsuite/msg/app-chainsend/iterator.c | 2 +- teshsuite/msg/cloud-migration/cloud-migration.c | 4 ++-- .../cloud-interrupt-migration/cloud-interrupt-migration.cpp | 2 +- teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp | 2 +- teshsuite/s4u/listen_async/listen_async.cpp | 2 +- teshsuite/s4u/pid/pid.cpp | 2 +- .../s4u/storage_client_server/storage_client_server.cpp | 6 +++--- teshsuite/simdag/flatifier/flatifier.cpp | 6 +++--- teshsuite/surf/surf_usage/surf_usage.cpp | 6 +++--- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index c3f876ea74..f43a8f8231 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -60,7 +60,7 @@ static void test_local_variable(simgrid::mc::ObjectInformation* info, const char assert(subprogram); // TODO, Lookup frame by IP and test against name instead - simgrid::mc::Variable* var = find_local_variable(subprogram, variable); + const simgrid::mc::Variable* var = find_local_variable(subprogram, variable); assert(var); void* frame_base = subprogram->frame_base(*cursor); @@ -83,7 +83,7 @@ static const simgrid::mc::Variable* test_global_variable(simgrid::mc::RemoteClie auto i = process.binary_info->types.find(variable->type_id); xbt_assert(i != process.binary_info->types.end(), "Missing type for %s", name); - simgrid::mc::Type* type = &i->second; + const simgrid::mc::Type* type = &i->second; xbt_assert(type->byte_size == byte_size, "Byte size mismatch for %s", name); return variable; } diff --git a/teshsuite/mc/mutex-handling/mutex-handling.c b/teshsuite/mc/mutex-handling/mutex-handling.c index c367cdf758..8eff02a140 100644 --- a/teshsuite/mc/mutex-handling/mutex-handling.c +++ b/teshsuite/mc/mutex-handling/mutex-handling.c @@ -48,7 +48,7 @@ static int receiver(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) static int sender(int argc, char *argv[]) { xbt_assert(argc == 2); - char* message_name = argv[1]; + const char* message_name = argv[1]; #ifndef DISABLE_THE_MUTEX sg_mutex_lock(mutex); #endif diff --git a/teshsuite/msg/app-chainsend/iterator.c b/teshsuite/msg/app-chainsend/iterator.c index bfffe74744..a96a090c1e 100644 --- a/teshsuite/msg/app-chainsend/iterator.c +++ b/teshsuite/msg/app-chainsend/iterator.c @@ -29,7 +29,7 @@ void* xbt_dynar_iterator_next(xbt_dynar_iterator_t it) if (it->current >= it->length) { return NULL; } else { - int* next = xbt_dynar_get_ptr(it->indices_list, it->current); + const int* next = xbt_dynar_get_ptr(it->indices_list, it->current); it->current++; return xbt_dynar_get_ptr(it->list, *next); } diff --git a/teshsuite/msg/cloud-migration/cloud-migration.c b/teshsuite/msg/cloud-migration/cloud-migration.c index d3603d7908..0391b563b3 100644 --- a/teshsuite/msg/cloud-migration/cloud-migration.c +++ b/teshsuite/msg/cloud-migration/cloud-migration.c @@ -23,8 +23,8 @@ static void vm_migrate(msg_vm_t vm, msg_host_t dst_pm) static int migration_worker_main(int argc, char* argv[]) { xbt_assert(argc == 3); - char* vm_name = argv[1]; - char* dst_pm_name = argv[2]; + const char* vm_name = argv[1]; + const char* dst_pm_name = argv[2]; msg_vm_t vm = (msg_vm_t)MSG_host_by_name(vm_name); msg_host_t dst_pm = MSG_host_by_name(dst_pm_name); diff --git a/teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration.cpp b/teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration.cpp index 0701ffa615..d2decb8053 100644 --- a/teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration.cpp +++ b/teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration.cpp @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_cloud_interrupt_migration, "Messages specific f static void vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) { - simgrid::s4u::Host* src_pm = vm->get_pm(); + const simgrid::s4u::Host* src_pm = vm->get_pm(); double mig_sta = simgrid::s4u::Engine::get_clock(); sg_vm_migrate(vm, dst_pm); double mig_end = simgrid::s4u::Engine::get_clock(); diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index 07838b53aa..e201a0eeed 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -143,7 +143,7 @@ static void receiver(std::vector args) default: xbt_die("Unknown receiver spec for test %u: '%c'", test, args[0][test - 1]); } - std::string* receivedStr = static_cast(received); + const std::string* receivedStr = static_cast(received); xbt_assert(*receivedStr == mboxName); delete receivedStr; XBT_INFO("Test %u OK", test); diff --git a/teshsuite/s4u/listen_async/listen_async.cpp b/teshsuite/s4u/listen_async/listen_async.cpp index 1e64d69f18..49a2185145 100644 --- a/teshsuite/s4u/listen_async/listen_async.cpp +++ b/teshsuite/s4u/listen_async/listen_async.cpp @@ -21,7 +21,7 @@ static void server() xbt_assert(mailbox->listen()); // True (1) XBT_INFO("Task listen works on regular mailboxes"); - std::string* res = static_cast(mailbox->get()); + const std::string* res = static_cast(mailbox->get()); xbt_assert(*res == "Some data", "Data received: %s", res->c_str()); XBT_INFO("Data successfully received from regular mailbox"); diff --git a/teshsuite/s4u/pid/pid.cpp b/teshsuite/s4u/pid/pid.cpp index 9f1099d9eb..af9aef752f 100644 --- a/teshsuite/s4u/pid/pid.cpp +++ b/teshsuite/s4u/pid/pid.cpp @@ -25,7 +25,7 @@ static void killall() { simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("mailbox"); for (int i = 0; i < 3; i++) { - int* pid = static_cast(mailbox->get()); + const int* pid = static_cast(mailbox->get()); XBT_INFO("Killing process \"%d\".", *pid); simgrid::s4u::Actor::by_pid(*pid)->kill(); } diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 79efb8ad31..0e780ac081 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -61,7 +61,7 @@ static void display_disk_content(simgrid::s4u::Disk* disk) { XBT_INFO("*** Dump a disk ***"); XBT_INFO("Print the content of the disk: %s", disk->get_cname()); - std::map* content = disk->extension()->get_content(); + const std::map* content = disk->extension()->get_content(); if (not content->empty()) { for (auto const& entry : *content) XBT_INFO(" %s size: %llu bytes", entry.first.c_str(), entry.second); @@ -74,7 +74,7 @@ static void get_set_disk_data(simgrid::s4u::Disk* disk) { XBT_INFO("*** GET/SET DATA for disk: %s ***", disk->get_cname()); - std::string* data = static_cast(disk->get_data()); + const std::string* data = static_cast(disk->get_data()); XBT_INFO("Get data: '%s'", data ? data->c_str() : "No User Data"); disk->set_data(new std::string("Some data")); data = static_cast(disk->get_data()); @@ -127,7 +127,7 @@ static void server() XBT_INFO("Server waiting for transfers ..."); while (1) { - std::string* msg = static_cast(mailbox->get()); + const std::string* msg = static_cast(mailbox->get()); if (*msg == "finalize") { // Shutdown ... delete msg; break; diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index da1a39aadf..338f43b87f 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -121,10 +121,10 @@ static void dump_routes() }); for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host - simgrid::s4u::Host* host1 = hosts[it_src]; + const simgrid::s4u::Host* host1 = hosts[it_src]; simgrid::kernel::routing::NetPoint* src = host1->get_netpoint(); for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host - simgrid::s4u::Host* host2 = hosts[it_dst]; + const simgrid::s4u::Host* host2 = hosts[it_dst]; std::vector route; simgrid::kernel::routing::NetPoint* dst = host2->get_netpoint(); simgrid::kernel::routing::NetZoneImpl::get_global_route(src, dst, route, nullptr); @@ -161,7 +161,7 @@ static void dump_routes() } } for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host - simgrid::s4u::Host* host2 = hosts[it_dst]; + const simgrid::s4u::Host* host2 = hosts[it_dst]; std::printf(" \n ", value1->get_cname(), host2->get_cname()); std::vector route; simgrid::kernel::routing::NetPoint* netcardDst = host2->get_netpoint(); diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 0d1238d551..953efb30d6 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -46,9 +46,9 @@ int main(int argc, char **argv) simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B"); /* Let's do something on it */ - simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0); - simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0); - simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32); + const simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0); + const simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0); + const simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32); simgrid::kernel::resource::Action::State stateActionA = actionA->get_state(); simgrid::kernel::resource::Action::State stateActionB = actionB->get_state(); -- 2.20.1