]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/bl: don't access raw::data directly. Use the getter instead.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 22 Jul 2020 18:57:51 +0000 (18:57 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 24 Jul 2020 13:23:00 +0000 (15:23 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/buffer.cc
src/include/buffer_raw.h

index 6ac87306c9322b6eab20c972690cb0f3e2fc3208..7e07667b3f6aa4adbce2497236dad456711ef985 100644 (file)
@@ -279,7 +279,7 @@ static ceph::spinlock debug_lock;
 
   ceph::unique_leakable_ptr<buffer::raw> buffer::copy(const char *c, unsigned len) {
     auto r = buffer::create_aligned(len, sizeof(size_t));
-    memcpy(r->data, c, len);
+    memcpy(r->get_data(), c, len);
     return r;
   }
 
@@ -288,7 +288,7 @@ static ceph::spinlock debug_lock;
   }
   ceph::unique_leakable_ptr<buffer::raw> buffer::create(unsigned len, char c) {
     auto ret = buffer::create_aligned(len, sizeof(size_t));
-    memset(ret->data, c, len);
+    memset(ret->get_data(), c, len);
     return ret;
   }
   ceph::unique_leakable_ptr<buffer::raw>
@@ -539,7 +539,7 @@ static ceph::spinlock debug_lock;
     return _raw->get_data()[_off + n];
   }
 
-  const char *buffer::ptr::raw_c_str() const { ceph_assert(_raw); return _raw->data; }
+  const char *buffer::ptr::raw_c_str() const { ceph_assert(_raw); return _raw->get_data(); }
   unsigned buffer::ptr::raw_length() const { ceph_assert(_raw); return _raw->len; }
   int buffer::ptr::raw_nref() const { ceph_assert(_raw); return _raw->nref; }
 
@@ -547,7 +547,7 @@ static ceph::spinlock debug_lock;
     ceph_assert(_raw);
     if (o+l > _len)
         throw end_of_buffer();
-    char* src =  _raw->data + _off + o;
+    char* src =  _raw->get_data() + _off + o;
     maybe_inline_memcpy(dest, src, l, 8);
   }
 
@@ -580,7 +580,7 @@ static ceph::spinlock debug_lock;
   {
     ceph_assert(_raw);
     ceph_assert(1 <= unused_tail_length());
-    char* ptr = _raw->data + _off + _len;
+    char* ptr = _raw->get_data() + _off + _len;
     *ptr = c;
     _len++;
     return _len + _off;
@@ -590,7 +590,7 @@ static ceph::spinlock debug_lock;
   {
     ceph_assert(_raw);
     ceph_assert(l <= unused_tail_length());
-    char* c = _raw->data + _off + _len;
+    char* c = _raw->get_data() + _off + _len;
     maybe_inline_memcpy(c, p, l, 32);
     _len += l;
     return _len + _off;
@@ -600,7 +600,7 @@ static ceph::spinlock debug_lock;
   {
     ceph_assert(_raw);
     ceph_assert(l <= unused_tail_length());
-    char* c = _raw->data + _off + _len;
+    char* c = _raw->get_data() + _off + _len;
     // FIPS zeroization audit 20191115: this memset is not security related.
     memset(c, 0, l);
     _len += l;
@@ -612,7 +612,7 @@ static ceph::spinlock debug_lock;
     ceph_assert(_raw);
     ceph_assert(o <= _len);
     ceph_assert(o+l <= _len);
-    char* dest = _raw->data + _off + o;
+    char* dest = _raw->get_data() + _off + o;
     if (crc_reset)
         _raw->invalidate_crc();
     maybe_inline_memcpy(dest, src, l, 64);
@@ -2179,7 +2179,7 @@ buffer::ptr_node* buffer::ptr_node::cloner::operator()(
 }
 
 std::ostream& buffer::operator<<(std::ostream& out, const buffer::raw &r) {
-  return out << "buffer::raw(" << (void*)r.data << " len " << r.len << " nref " << r.nref.load() << ")";
+  return out << "buffer::raw(" << (void*)r.get_data() << " len " << r.len << " nref " << r.nref.load() << ")";
 }
 
 std::ostream& buffer::operator<<(std::ostream& out, const buffer::ptr& bp) {
index 6483edd73f96d896582cd1755c4d68d1f70097cb..fe59860d5e9c74d433e7eb05ea327f2b2755d94b 100644 (file)
@@ -32,7 +32,9 @@ inline namespace v15_2_0 {
     // embedded slots. This would allow to avoid the "if" in dtor of ptr_node.
     std::aligned_storage<sizeof(ptr_node),
                         alignof(ptr_node)>::type bptr_storage;
+  protected:
     char *data;
+  public:
     unsigned len;
     ceph::atomic<unsigned> nref { 0 };
     int mempool;
@@ -84,7 +86,7 @@ private:
     raw(const raw &other) = delete;
     const raw& operator=(const raw &other) = delete;
 public:
-    char *get_data() {
+    char *get_data() const {
       return data;
     }
     virtual raw* clone_empty() = 0;