Ticket #8698 (closed Bugs: fixed)
Boost.Intrusive unordered_set should use different value for end()
|Reported by:||jody_boost@…||Owned by:||igaztanaga|
|Milestone:||To Be Determined||Component:||intrusive|
The current implementation uses one-past the end of the provided buckets array as the special value for end().
While this is generally OK, there are cases where it is problematic (i.e., the collection is now unusable). Specifically, consider where the buckets array is created on the stack, and the objects are also on the stack. The compiler can (and gcc does) reorder stack variables. If this happens in just the right way, you can end up with an object that you add to the collection living at the address of the special end marker.
If this happens, then the insert is successful (the cached size even increments), but since the pointer to the inserted value has the same value as end(), then finding and iterating is now broken.
Furthermore, if both the bucket array and objectes inserted are allocated from the heap, then the possibility of the above is still present (though unlikely).
Unfortunately, this has actually happened to me so that I now allocate an extra bucket in the bucket array and pass size as N-1. This wastes a bucket that is never used, but prevents the horrible bug of inserting an object, but not finding it...
- Owner set to igaztanaga
- Component changed from None to intrusive