From e45e700f6491fcd0972c5409dda3c5fb63de14d3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 19 May 2008 10:45:19 -0700 Subject: [PATCH] buffer: fix 0-byte bufferptr behavior, encoding --- src/include/buffer.h | 8 ++++++-- src/include/encoding.h | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/include/buffer.h b/src/include/buffer.h index 2b98bf9d9623..b6b0774e1d5b 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -88,7 +88,10 @@ private: class raw_char : public raw { public: raw_char(unsigned l) : raw(l) { - data = new char[len]; + if (len) + data = new char[len]; + else + data = 0; inc_total_alloc(len); } ~raw_char() { @@ -754,7 +757,8 @@ public: } } void append(const ptr& bp) { - push_back(bp); + if (bp.length()) + push_back(bp); } void append(const ptr& bp, unsigned off, unsigned len) { assert(len+off <= bp.length()); diff --git a/src/include/encoding.h b/src/include/encoding.h index 3c2538bb2db1..10aee22210d2 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -375,7 +375,8 @@ inline void encode(const buffer::ptr& bp, bufferlist& bl) { __u32 len = bp.length(); encode(len, bl); - bl.append(bp); + if (len) + bl.append(bp); } inline void decode(buffer::ptr& bp, bufferlist::iterator& p) { @@ -385,10 +386,12 @@ inline void decode(buffer::ptr& bp, bufferlist::iterator& p) bufferlist s; p.copy(len, s); - if (s.buffers().size() == 1) - bp = s.buffers().front(); - else - bp = buffer::copy(s.c_str(), s.length()); + if (len) { + if (s.buffers().size() == 1) + bp = s.buffers().front(); + else + bp = buffer::copy(s.c_str(), s.length()); + } } // bufferlist (encapsulated) -- 2.47.3