Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make PrincipalSet::NameIterator::get() valid between the first calls …

…to more() and next()

This makes get() invalid after calling next() but before calling more()
  • Loading branch information...
commit 925f701ace23755b36e428f1dce332a522805463 1 parent bb8b3e5
@RedBeard0531 RedBeard0531 authored
View
10 src/mongo/db/auth/principal_set.h
@@ -34,9 +34,12 @@ namespace mongo {
MONGO_DISALLOW_COPYING(PrincipalSet);
public:
/**
- * Forward iterator over the names of the principals stored in a PrincpalSet.
+ * Forward iterator over the names of the principals stored in a PrincipalSet.
*
* Instances are valid until the underlying vector<Principal*> is modified.
+ *
+ * more() must be the first method called after construction, and must be checked
+ * after each call to next() before calling any other methods.
*/
class NameIterator {
public:
@@ -49,11 +52,12 @@ namespace mongo {
bool more() { return _curr != _end; }
const PrincipalName& next() {
+ const PrincipalName& ret = get();
++_curr;
- return get();
+ return ret;
}
- const PrincipalName& get() const { return (*(_curr - 1))->getName(); }
+ const PrincipalName& get() const { return (*_curr)->getName(); }
const PrincipalName& operator*() const { return get(); }
const PrincipalName* operator->() const { return &get(); }
View
2  src/mongo/db/auth/principal_set_test.cpp
@@ -88,8 +88,8 @@ namespace {
iter = pset.getNames();
ASSERT(iter.more());
- ASSERT_EQUALS(iter.next(), PrincipalName("bob", "test"));
ASSERT_EQUALS(*iter, PrincipalName("bob", "test"));
+ ASSERT_EQUALS(iter.next(), PrincipalName("bob", "test"));
ASSERT(!iter.more());
}
Please sign in to comment.
Something went wrong with that request. Please try again.