summaryrefslogtreecommitdiff
path: root/src/context
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2011-03-25 05:20:56 +0000
committerMorgan Deters <mdeters@gmail.com>2011-03-25 05:20:56 +0000
commitee36b95b8f722fe6501cc6ac635efd49ca673791 (patch)
treeb6149a6b843b26b65db788d0cf3215dd68d53e79 /src/context
parent33239a85e160bcbdfa23b44e316065166e361af8 (diff)
Fix for a bug Andrew Reynolds found for iterators that affects empty CDList<> objects that allocate from ContextMemoryAllocator<>. Iterators were broken in that begin() != end() for empty lists (again---only those that allocated space from ContextMemoryAllocator<>). Added a unit test for this, too. Thanks Andy!
Diffstat (limited to 'src/context')
-rw-r--r--src/context/cdlist_context_memory.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/context/cdlist_context_memory.h b/src/context/cdlist_context_memory.h
index 20d672d31..2fd1ceb8c 100644
--- a/src/context/cdlist_context_memory.h
+++ b/src/context/cdlist_context_memory.h
@@ -476,7 +476,11 @@ public:
* Returns an iterator pointing to the first item in the list.
*/
const_iterator begin() const {
- return const_iterator(&d_headSegment, 0);
+ // This looks curious, but we have to make sure that begin() == end()
+ // for an empty list, and begin() == (head,0) for a nonempty one.
+ // Since the segment spill-over is implemented in
+ // iterator::operator++(), let's reuse it. */
+ return ++const_iterator(&d_headSegment, -1);
}
/**
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback