[asio] Invalidated iterator bug in hash_map

Hi, the file hash_map.hpp has a bug, caught by STLPort checked-STL. The clear member-function is: // Remove all entries from the map. void clear() { // Initialise all buckets to empty. for (size_t i = 0; i < num_buckets; ++i) buckets_[i].first = buckets_[i].last = values_.end(); // Clear the values. values_.clear(); } But the clear member function of values_invalidates all iterators. So, the values recorded in the buckets are all invalidated. Which is caught in a later call to insert. I've swapped the clear call above the for and everything is fine here. best regards, -- Felipe Magno de Almeida

Hi Felipe, --- Felipe Magno de Almeida <felipe.m.almeida@gmail.com> wrote:
the file hash_map.hpp has a bug, caught by STLPort checked-STL. The clear member-function is:
// Remove all entries from the map. void clear() { // Initialise all buckets to empty. for (size_t i = 0; i < num_buckets; ++i) buckets_[i].first = buckets_[i].last = values_.end();
// Clear the values. values_.clear(); }
But the clear member function of values_invalidates all iterators. So, the values recorded in the buckets are all invalidated. Which is caught in a later call to insert.
I've swapped the clear call above the for and everything is fine here.
No problem, I'll change it as soon as sourceforge cvs is working again. However, I do wonder if it's STLPort's checked iterator support that has the bug. 23.2.2.3/3 specifies the effects of clear(), and says: Invalidates only the iterators and references to the erased elements. To me this means that the iterator returned by end() is not invalidated by the call to clear(), since that iterator does not correspond to any element that can be erased. Perhaps there is another part of the standard that says otherwise? Cheers, Chris

On 4/4/06, Christopher Kohlhoff <chris@kohlhoff.com> wrote:
Hi Felipe,
Hello Christopher, [snipped]
No problem, I'll change it as soon as sourceforge cvs is working again. However, I do wonder if it's STLPort's checked iterator support that has the bug. 23.2.2.3/3 specifies the effects of clear(), and says:
thanks, I dont know very much to confirm, but really looks like a bug in STLPort checked iterator.
Invalidates only the iterators and references to the erased elements.
To me this means that the iterator returned by end() is not invalidated by the call to clear(), since that iterator does not correspond to any element that can be erased. Perhaps there is another part of the standard that says otherwise?
I think you're right. But, IMO, it is a very trivial workaround, anyway...
Cheers, Chris
Thank you very much, -- Felipe Magno de Almeida
participants (2)
-
Christopher Kohlhoff
-
Felipe Magno de Almeida