|
From: | Markus Schiltknecht |
Subject: | [Monotone-devel] set's erase() and iterators |
Date: | Tue, 16 Oct 2007 21:33:56 +0200 |
User-agent: | Icedove 1.5.0.10 (X11/20070328) |
Hello Will,on my box, monotone's suspend test reproducibly failed. Today I've tracked down the bug, which took me quite some time.
When erasing from a set<>, most iterators remain valid, except the one you've just erased (of course!). But that in turn means, that the following code in project.cc could lead to a segmentation fault (probably also dependent on the STL implementation):
for(std::set<revision_id>::iterator it = branch.second.begin(); it != branch.second.end(); ++it) if (some_decision_func(...)) branch.second.erase(*it);It's one of the less obvious things in the STL, and about everybody has stumbled over it before, at least I did already several times ;-)
One option to circumvent that problem is recreating the set, as I did for project.cc now. Another option might be using the STL algorithm remove_if().
Regards Markus
[Prev in Thread] | Current Thread | [Next in Thread] |