mirror of
https://github.com/ceph/ceph
synced 2025-01-29 22:43:40 +00:00
Merge pull request #53 from dachary/wip-4123
fix buffer::list::zero(unsigned o, unsigned l) to act on all buffer::ptr Backport: bobtail Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
commit
ffbc085de1
@ -736,7 +736,7 @@ bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
|
||||
it != _buffers.end();
|
||||
it++) {
|
||||
if (p + it->length() > o) {
|
||||
if (p >= o && p+it->length() >= o+l)
|
||||
if (p >= o && p+it->length() <= o+l)
|
||||
it->zero(); // all
|
||||
else if (p >= o)
|
||||
it->zero(0, o+l-p); // head
|
||||
@ -744,7 +744,7 @@ bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
|
||||
it->zero(o-p, it->length()-(o-p)); // tail
|
||||
}
|
||||
p += it->length();
|
||||
if (o+l >= p)
|
||||
if (o+l <= p)
|
||||
break; // done
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,53 @@
|
||||
|
||||
#define MAX_TEST 1000000
|
||||
|
||||
TEST(BufferList, zero) {
|
||||
//
|
||||
// void zero()
|
||||
//
|
||||
{
|
||||
bufferlist bl;
|
||||
bl.append('A');
|
||||
EXPECT_EQ('A', bl[0]);
|
||||
bl.zero();
|
||||
EXPECT_EQ('\0', bl[0]);
|
||||
}
|
||||
//
|
||||
// void zero(unsigned o, unsigned l)
|
||||
//
|
||||
const char *s[] = {
|
||||
"ABC",
|
||||
"DEF",
|
||||
"GHI",
|
||||
"KLM"
|
||||
};
|
||||
{
|
||||
bufferlist bl;
|
||||
bufferptr ptr(s[0], strlen(s[0]));
|
||||
bl.push_back(ptr);
|
||||
bl.zero((unsigned)0, (unsigned)1);
|
||||
EXPECT_EQ(0, ::memcmp("\0BC", bl.c_str(), 3));
|
||||
}
|
||||
{
|
||||
bufferlist bl;
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
bufferptr ptr(s[i], strlen(s[i]));
|
||||
bl.push_back(ptr);
|
||||
}
|
||||
EXPECT_THROW(bl.zero((unsigned)0, (unsigned)2000), FailedAssertion);
|
||||
bl.zero((unsigned)2, (unsigned)5);
|
||||
EXPECT_EQ(0, ::memcmp("AB\0\0\0\0\0HIKLM", bl.c_str(), 9));
|
||||
}
|
||||
{
|
||||
bufferlist bl;
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
bufferptr ptr(s[i], strlen(s[i]));
|
||||
bl.push_back(ptr);
|
||||
}
|
||||
bl.zero((unsigned)3, (unsigned)3);
|
||||
EXPECT_EQ(0, ::memcmp("ABC\0\0\0GHIKLM", bl.c_str(), 9));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BufferList, EmptyAppend) {
|
||||
bufferlist bl;
|
||||
|
Loading…
Reference in New Issue
Block a user