]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async: avoid referencing the temporary string 20640/head
authorKefu Chai <kchai@redhat.com>
Wed, 28 Feb 2018 11:15:19 +0000 (19:15 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 28 Feb 2018 11:23:56 +0000 (19:23 +0800)
* 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

index 3e577d0aed6216c6201a74c4a05201227f017024..4c1cf9f023792f4fe69a2a79909f573e0d92f1f0 100644 (file)
@@ -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);