]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: fix 0-byte bufferptr behavior, encoding
authorSage Weil <sage@newdream.net>
Mon, 19 May 2008 17:45:19 +0000 (10:45 -0700)
committerSage Weil <sage@newdream.net>
Mon, 19 May 2008 17:45:19 +0000 (10:45 -0700)
src/include/buffer.h
src/include/encoding.h

index 2b98bf9d9623047da31c936204bebe26ca166541..b6b0774e1d5b3172b93f421223291bc10b31e176 100644 (file)
@@ -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());
index 3c2538bb2db1c689cac100f09d0b35f719dc6e88..10aee22210d22238756647f7a81dc184e3623a5a 100644 (file)
@@ -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)