]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: use homebrew BUF_OFFSETOF to replace offsetof() 37097/head
authorKefu Chai <kchai@redhat.com>
Fri, 11 Sep 2020 04:53:28 +0000 (12:53 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 11 Sep 2020 04:56:22 +0000 (12:56 +0800)
because buffer::raw is not a standard layout type. so `offsetof()`
does not always work. let's use a homebrew macro to calculate the
address of `bptr_storage`.

this change silences the warning like:

src/common/buffer.cc:2156:15: warning: ‘offsetof’ within non-standard-layout type ‘ceph::buffer::v15_2_0::raw’ is conditionally-supported [-Winvalid-offsetof]
 2156 |      offsetof(buffer::raw, bptr_storage));

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/buffer.cc

index b71af2ec75e9e0d678bb35fe718bcf9ce3e724ad..f8b0a65d269009d3956fcd0b5c18f7fb3508729e 100644 (file)
@@ -2147,13 +2147,17 @@ buffer::list buffer::list::static_from_string(string& s) {
   // const makes me generally sad.
 }
 
+// buffer::raw is not a standard layout type.
+#define BUF_OFFSETOF(type, field)                                      \
+  (reinterpret_cast<std::uintptr_t>(&(((type*)1024)->field)) - 1024u)
+
 bool buffer::ptr_node::dispose_if_hypercombined(
   buffer::ptr_node* const delete_this)
 {
   // in case _raw is nullptr
   const std::uintptr_t bptr =
     (reinterpret_cast<std::uintptr_t>(delete_this->_raw) +
-     offsetof(buffer::raw, bptr_storage));
+     BUF_OFFSETOF(buffer::raw, bptr_storage));
   const bool is_hypercombined =
     reinterpret_cast<std::uintptr_t>(delete_this) == bptr;
   if (is_hypercombined) {