From a2f65d78c3485f154e5724abfcd0df8395c54c6a Mon Sep 17 00:00:00 2001 From: Kefu Chai <kchai@redhat.com> Date: Wed, 28 Feb 2018 19:15:19 +0800 Subject: [PATCH] msg/async: avoid referencing the temporary string * get_val<std::string>(...) returns a temporary std::string, so we cannot keep a reference to it after evaluating this method. so convert it to an integer right away in the same expression. * use std::stoull() with base = 16, so we can parse a hex string representing up to 64 bits. Signed-off-by: Kefu Chai <kchai@redhat.com> --- src/msg/async/dpdk/dpdk_rte.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/msg/async/dpdk/dpdk_rte.cc b/src/msg/async/dpdk/dpdk_rte.cc index 3e577d0aed6..4c1cf9f0237 100644 --- a/src/msg/async/dpdk/dpdk_rte.cc +++ b/src/msg/async/dpdk/dpdk_rte.cc @@ -40,7 +40,7 @@ namespace dpdk { std::condition_variable eal::cond; std::list<std::function<void()>> eal::funcs; - static int bitcount(unsigned n) + static int bitcount(unsigned long long n) { return std::bitset<CHAR_BIT * sizeof(n)>{n}.count(); } @@ -52,8 +52,8 @@ namespace dpdk { } bool done = false; - const char *hexstring = c->_conf->get_val<std::string>("ms_dpdk_coremask").c_str(); - int num = (int)strtol(hexstring, NULL, 0); + auto num = std::stoull(c->_conf->get_val<std::string>("ms_dpdk_coremask"), + nullptr, 16); unsigned int coremaskbit = bitcount(num); ceph_assert(coremaskbit > c->_conf->ms_async_op_threads);