From 5f5c7f3f5dc70d6b6bf774000de4bf4b839c81a6 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 10 Jul 2018 11:36:36 +0200 Subject: [PATCH] char* are banned --- src/plugins/link_energy.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index 28a60208b8..a0b7cd413f 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -103,14 +103,18 @@ void LinkEnergy::init_watts_range_list() /* min_power corresponds to the idle power (link load = 0) */ /* max_power is the power consumed at 100% link load */ - char* idleMsg = bprintf("Invalid idle power value for link%s", this->link_->get_cname()); - char* busyMsg = bprintf("Invalid busy power value for %s", this->link_->get_cname()); + try { + idle_ = std::stod(current_power_values.front()); + } catch (std::invalid_argument& ia) { + throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname()); + } + + try { + busy_ = std::stod(current_power_values.back()); + } catch (std::invalid_argument& ia) { + throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname()); + } - idle_ = xbt_str_parse_double((current_power_values.at(0)).c_str(), idleMsg); - busy_ = xbt_str_parse_double((current_power_values.at(1)).c_str(), busyMsg); - - xbt_free(idleMsg); - xbt_free(busyMsg); update(); } } -- 2.20.1