From: Arnaud Giersch Date: Mon, 14 Aug 2017 21:18:06 +0000 (+0200) Subject: Avoid short-lied temporary string. X-Git-Tag: v3_17~152^2~33 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2d5c35e78ac07044be9866ca4adc06bb5010070c Avoid short-lied temporary string. --- diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index 68dfbc0728..6b70db209d 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -50,8 +50,8 @@ static void sender(std::vector args) XBT_INFO("Sender spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str(); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); + std::string* mboxName = new std::string("Test #" + std::to_string(test)); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName->c_str()); switch (args[0][test - 1]) { case 'r': @@ -97,8 +97,8 @@ static void receiver(std::vector args) XBT_INFO("Receiver spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str(); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); + std::string mboxName = "Test #" + std::to_string(test); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName.c_str()); void* received = nullptr; switch (args[0][test - 1]) { @@ -146,8 +146,9 @@ static void receiver(std::vector args) default: xbt_die("Unknown receiver spec for test %u: '%c'", test, args[0][test - 1]); } - - xbt_assert(strcmp(static_cast(received), mboxName) == 0); + std::string* receivedStr = static_cast(received); + xbt_assert(*receivedStr == mboxName); + delete receivedStr; XBT_INFO("Test %u OK", test); } simgrid::s4u::this_actor::sleep_for(0.5);