]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
fix buffer::list::zero(unsigned o, unsigned l) to act on all buffer::ptr 53/head
authorLoic Dachary <loic@dachary.org>
Thu, 14 Feb 2013 11:05:54 +0000 (12:05 +0100)
committerLoic Dachary <loic@dachary.org>
Thu, 14 Feb 2013 12:46:56 +0000 (13:46 +0100)
commit02a353e5940e003cfcdffc77920a6b518d581d95
tree181bea4e1115d6953c16dbc81516b02da0ebc83e
parentccdcae3a544e9dee27c8d1229e5a0ef7383152de
fix buffer::list::zero(unsigned o, unsigned l) to act on all buffer::ptr

When buffer::list::zero was called on a buffer::list with "ABC" and
"DEF" in two different buffer::ptr with buffer::list::zero(4, 1) it
did nothing. The expected result is that the "DEF" buffer::ptr is
modified to "D\0F"

The test to check if the pointer is past the end of range to be zeroed
was reversed. It was o+l >= p which would always be true if the range
spans over the first buffer::ptr . It must be "o+l <= p" meaning the
pointer is past the end of the range and there is no need to loop over
the remaining buffer::ptr in the buffer::list

The p+it->length() >= o+l part of the if (p >= o && p+it->length() >=
o+l) test was also reversed. When called on "ABC" with zero(0, 1) it
would match because the range to be zeroed is contained in the
buffer::ptr. The call to it->zero() would zero the entire buffer::ptr
instead of just the first character.

unit tests are added to demonstrate the two problems with the previous
code and show that the patch fixes them.

http://tracker.ceph.com/issues/4123 refs #4123

Signed-off-by: Loic Dachary <loic@dachary.org>
src/common/buffer.cc
src/test/bufferlist.cc