Skip to content

Commit

Permalink
librados: fix ObjectIterator::operator= for the end iterator
Browse files Browse the repository at this point in the history
We can't set a shared_ptr to NULL, we need to reset it instead. Add
another test for various permutations of this.

Fixes: ceph#7538
Signed-off-by: Josh Durgin <[email protected]>
  • Loading branch information
jdurgin committed Feb 28, 2014
1 parent 7ba3200 commit bfad17b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librados/librados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ librados::ObjectIterator& librados::ObjectIterator::operator=(const librados::Ob
{
if (&rhs == this)
return *this;
if (rhs.ctx.get() == NULL) {
ctx.reset();
return *this;
}
Objecter::ListContext *list_ctx = new Objecter::ListContext(*rhs.ctx->lc);
ctx.reset(new ObjListCtx(rhs.ctx->ctx, list_ctx));
cur_obj = rhs.cur_obj;
Expand Down
25 changes: 25 additions & 0 deletions src/test/librados/list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ TEST_F(LibRadosListPP, ListObjectsCopyIterPP) {
ASSERT_TRUE(iter3 == ioctx.objects_end());
}

TEST_F(LibRadosListPP, ListObjectsEndIter) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl1, sizeof(buf), 0));

ObjectIterator iter(ioctx.objects_begin());
ObjectIterator iter_end(ioctx.objects_end());
ObjectIterator iter_end2 = ioctx.objects_end();
ASSERT_TRUE(iter_end == iter_end2);
ASSERT_TRUE(iter_end == ioctx.objects_end());
ASSERT_TRUE(iter_end2 == ioctx.objects_end());

ASSERT_EQ(iter->first, "foo");
++iter;
ASSERT_TRUE(iter == ioctx.objects_end());
ASSERT_TRUE(iter == iter_end);
ASSERT_TRUE(iter == iter_end2);
ObjectIterator iter2 = iter;
ASSERT_TRUE(iter2 == ioctx.objects_end());
ASSERT_TRUE(iter2 == iter_end);
ASSERT_TRUE(iter2 == iter_end2);
}

static void check_list(std::set<std::string>& myset, rados_list_ctx_t& ctx)
{
const char *entry;
Expand Down

0 comments on commit bfad17b

Please sign in to comment.