[v3] libstdc++/54296

François Dumont frs.dumont@gmail.com
Tue Aug 28 10:08:00 GMT 2012


Hi

     Here is the patch for this issue. I introduced 2 distinct methods 
to erase elements from a key. The one when keys are unique is rather 
simple and now use the same underlying code that the erase method from 
iterator. The other one when keys are not unique first look for nodes 
matching the key and deallocate those in a second loop so that it 
doesn't invalidate the key while looking for nodes. I considered 
checking if the key instance address was inside the node address space 
but the key instance might also be referenced as a pointer in the value 
type free when the value instance is destroyed. Separating is the only 
way to be sure that the key won't be broken while looking for matching 
nodes.

     I check that _Rb_tree is not impacted by this issue as it is using 
a call to equal_range first and erase the range after. I considered 
doing the same in _Hashtable implementation but finally preferred not to 
do so because it would imply re-computing hash code and add useless checks.

2012-08-28  François Dumont <fdumont@gcc.gnu.org>

     PR libstdc++/54296
     * include/bits/hashtable.h (_M_erase(size_type, __node_base*,
     __node_type*)): New.
     (erase(const_iterator)): Use latter.
     (_M_erase(std::true_type, const key_type&)): New, likewise.
     (_M_erase(std::false_type, const key_type&)): New. Find all nodes
     matching the key before deallocating them so that the key doesn't
     get invalidated.
     (erase(const key_type&)): Use latters.
     * testsuite/23_containers/unordered_map/erase/54296.cc: New.
     * testsuite/23_containers/unordered_multimap/erase/54296.cc: New.

Tested under linux x86_64.

Ok for trunk ? As it is an old issue I don't think it needs to be apply 
to any branch, tell me otherwise.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 10685 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120828/eaaebfb0/attachment.bin>


More information about the Libstdc++ mailing list