boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
103 stars 113 forks source link

flat_set: undefined behaviour on empty range #76

Closed gjasny closed 6 years ago

gjasny commented 6 years ago

Hello,

the following code triggers the undefined behaviour sanitiser:

#include <cstdint>
#include <boost/container/flat_set.hpp>

using PacketSet = boost::container::flat_set<std::uint32_t>;

int main(int argc, const char * argv[]) {

    const PacketSet empty;
    PacketSet target;
    target.insert(empty.begin(), empty.end());

    return 0;
}

Output is:

boost/V1.67.0_6/boost/container/vector.hpp:125:14: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/container/vector.hpp:128:76: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/intrusive/pointer_traits.hpp:292:49: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/move/detail/meta_utils.hpp:270:49: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/move/detail/meta_utils.hpp:246:55: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/move/detail/meta_utils.hpp:247:57: runtime error: reference binding to null pointer of type 'unsigned int'
boost/V1.67.0_6/boost/move/detail/meta_utils.hpp:270:9: runtime error: reference binding to null pointer of type 'unsigned int'

Thanks, Gregor

gjasny commented 6 years ago

@igaztanaga: I don't know if you get notified automatically.

igaztanaga commented 6 years ago

It seems that

https://github.com/boostorg/container/commit/b56cbb60e05cc06fbebed03f8b359b116e788f2a

fixes it (operator-> should not be based on operator*). Thanks for the report.

gjasny commented 6 years ago

Thanks, verified.