From 43f583d160ccaf879eaf0f3020e77860cf8d1df0 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Thu, 9 Jul 2015 13:42:42 +0800 Subject: [PATCH] buffer: Fix bufferlist::zero bug with special case Fixes: #12252 Signed-off-by: Haomai Wang --- src/common/buffer.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 5124b8c50f421..86dc6d8d0ddc9 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1166,12 +1166,23 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; it != _buffers.end(); ++it) { if (p + it->length() > o) { - if (p >= o && p+it->length() <= o+l) - it->zero(); // all - else if (p >= o) - it->zero(0, o+l-p); // head - else - it->zero(o-p, it->length()-(o-p)); // tail + if (p >= o && p+it->length() <= o+l) { + // 'o'------------- l -----------| + // 'p'-- it->length() --| + it->zero(); + } else if (p >= o) { + // 'o'------------- l -----------| + // 'p'------- it->length() -------| + it->zero(0, o+l-p); + } else if (p + it->length() <= o+l) { + // 'o'------------- l -----------| + // 'p'------- it->length() -------| + it->zero(o-p, it->length()-(o-p)); + } else { + // 'o'----------- l -----------| + // 'p'---------- it->length() ----------| + it->zero(o-p, l); + } } p += it->length(); if (o+l <= p) -- 2.39.5