]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: fix advance(unsigned) to avoid int underflow
authorKefu Chai <kchai@redhat.com>
Tue, 7 Jun 2016 03:20:06 +0000 (11:20 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 7 Jun 2016 03:23:28 +0000 (11:23 +0800)
by chaning
- the signature of advance(unsigned) to advance(size_t)
- the signature of seek(int) to seek(ssize_t)

Fixes: http://tracker.ceph.com/issues/16010
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/buffer.cc
src/include/buffer.h

index be6fa65eda5d44aed4b38d7c38f8ea8d84f49523..19b4cd2ef7c6d4896d83401fc42528bf1ce544ef 100644 (file)
@@ -1041,7 +1041,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     : iterator_impl<is_const>(i.bl, i.off, i.p, i.p_off) {}
 
   template<bool is_const>
-  void buffer::list::iterator_impl<is_const>::advance(int o)
+  void buffer::list::iterator_impl<is_const>::advance(ssize_t o)
   {
     //cout << this << " advance " << o << " from " << off << " (p_off " << p_off << " in " << p->length() << ")" << std::endl;
     if (o > 0) {
@@ -1080,7 +1080,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
   }
 
   template<bool is_const>
-  void buffer::list::iterator_impl<is_const>::seek(unsigned o)
+  void buffer::list::iterator_impl<is_const>::seek(size_t o)
   {
     p = ls->begin();
     off = p_off = 0;
@@ -1247,12 +1247,12 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     : iterator_impl(l, o, ip, po)
   {}
 
-  void buffer::list::iterator::advance(int o)
+  void buffer::list::iterator::advance(ssize_t o)
   {
     buffer::list::iterator_impl<false>::advance(o);
   }
 
-  void buffer::list::iterator::seek(unsigned o)
+  void buffer::list::iterator::seek(size_t o)
   {
     buffer::list::iterator_impl<false>::seek(o);
   }
index 9998573237861bbe86b2b33a1174b8f8de129640..49fd999ee6dfef100215606972a359c661d78dee 100644 (file)
@@ -308,8 +308,8 @@ namespace buffer CEPH_BUFFER_API {
        //return off == bl->length();
       }
 
-      void advance(int o);
-      void seek(unsigned o);
+      void advance(ssize_t o);
+      void seek(size_t o);
       char operator*() const;
       iterator_impl& operator++();
       ptr get_current_ptr() const;
@@ -351,8 +351,8 @@ namespace buffer CEPH_BUFFER_API {
       iterator(bl_t *l, unsigned o=0);
       iterator(bl_t *l, unsigned o, list_iter_t ip, unsigned po);
 
-      void advance(int o);
-      void seek(unsigned o);
+      void advance(ssize_t o);
+      void seek(size_t o);
       char operator*();
       iterator& operator++();
       ptr get_current_ptr();