]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/WPQ: add sanity check to avoid potential access violation
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 8 Aug 2016 07:49:39 +0000 (15:49 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 11 Aug 2016 22:35:17 +0000 (06:35 +0800)
For dump command, it will be the normal case that rbtree is empty(),
so get_cost() is at risk of accessing violation.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/common/WeightedPriorityQueue.h

index a94ff2d30948ce2aa7cc94f08166c985df85ee29..bef8bc01dbc096e64486d3e056962fd0cbd0e865 100644 (file)
@@ -84,7 +84,8 @@ class WeightedPriorityQueue :  public OpQueue <T, K>
       }
       //Get the cost of the next item to dequeue
       unsigned get_cost() const {
-       return lp.begin()->cost;
+        assert(!empty());
+        return lp.begin()->cost;
       }
       T pop() {
        assert(!lp.empty());
@@ -166,7 +167,8 @@ class WeightedPriorityQueue :  public OpQueue <T, K>
        ret.first->insert(cost, item, front);
       }
       unsigned get_cost() const {
-       return next->get_cost();
+        assert(!empty());
+        return next->get_cost();
       }
       T pop() {
         T ret = next->pop();
@@ -211,8 +213,10 @@ class WeightedPriorityQueue :  public OpQueue <T, K>
        return count;
       }
       void dump(ceph::Formatter *f) const {
-       f->dump_int("num_keys", next->get_size());
-       f->dump_int("first_item_cost", next->get_cost());
+        f->dump_int("num_keys", next->get_size());
+        if (!empty()) {
+          f->dump_int("first_item_cost", next->get_cost());
+        }
       }
     };
     class Queue {