[Boost-bugs] [Boost C++ Libraries] #8698: Boost.Intrusive unordered_set should use different value for end()

Subject: [Boost-bugs] [Boost C++ Libraries] #8698: Boost.Intrusive unordered_set should use different value for end()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-14 17:40:25


#8698: Boost.Intrusive unordered_set should use different value for end()
--------------------------+------------------------------
 Reporter: jody_boost@… | Type: Bugs
   Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.53.0
 Severity: Problem | Keywords:
--------------------------+------------------------------
 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...

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8698>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC