From de59926d9596010cd9e9331cc9d6c2e602b814c9 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 13 Jul 2016 15:19:25 +0800 Subject: [PATCH] os/bluestore: count length of SPDK_PREFIX in a more human-readable way The strlen() will automatically exclude the NUL terminator of a literal constant. Also by calling strlen(), we know that we are definitely operate on a string instead of something odd. Signed-off-by: xie xingguo --- src/os/bluestore/BlueStore.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index f3b97bd8a128..0352fceef1a4 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2432,7 +2432,7 @@ int BlueStore::_setup_block_symlink_or_file( if (create) flags |= O_CREAT; if (epath.length()) { - if (!epath.compare(0, sizeof(SPDK_PREFIX)-1, SPDK_PREFIX)) { + if (!epath.compare(0, strlen(SPDK_PREFIX), SPDK_PREFIX)) { r = ::symlinkat(epath.c_str(), path_fd, name.c_str()); if (r < 0) { r = -errno; @@ -2447,7 +2447,7 @@ int BlueStore::_setup_block_symlink_or_file( << cpp_strerror(r) << dendl; return r; } - string serial_number = epath.substr(sizeof(SPDK_PREFIX)-1); + string serial_number = epath.substr(strlen(SPDK_PREFIX)); r = ::write(fd, serial_number.c_str(), serial_number.size()); assert(r == (int)serial_number.size()); dout(1) << __func__ << " created " << name << " file with " << dendl; -- 2.47.3