From: Kefu Chai Date: Wed, 28 Feb 2018 11:15:19 +0000 (+0800) Subject: msg/async: avoid referencing the temporary string X-Git-Tag: v13.0.2~127^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a2f65d78c3485f154e5724abfcd0df8395c54c6a;p=ceph.git msg/async: avoid referencing the temporary string * get_val(...) 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 --- diff --git a/src/msg/async/dpdk/dpdk_rte.cc b/src/msg/async/dpdk/dpdk_rte.cc index 3e577d0aed62..4c1cf9f02379 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> eal::funcs; - static int bitcount(unsigned n) + static int bitcount(unsigned long long n) { return std::bitset{n}.count(); } @@ -52,8 +52,8 @@ namespace dpdk { } bool done = false; - const char *hexstring = c->_conf->get_val("ms_dpdk_coremask").c_str(); - int num = (int)strtol(hexstring, NULL, 0); + auto num = std::stoull(c->_conf->get_val("ms_dpdk_coremask"), + nullptr, 16); unsigned int coremaskbit = bitcount(num); ceph_assert(coremaskbit > c->_conf->ms_async_op_threads);