forked from boostorg/fusion
Fix out of bounds access within {front|back}_extended_deque with empty deque.
The insertion point is not correct with empty deque since the range {next_down, next_up} is not half-open range.
This commit is contained in:
@ -50,7 +50,7 @@ namespace boost { namespace fusion
|
||||
typedef bidirectional_traversal_tag category;
|
||||
typedef mpl::int_<0> size;
|
||||
typedef mpl::int_<0> next_up;
|
||||
typedef mpl::int_<0> next_down;
|
||||
typedef mpl::int_<-1> next_down;
|
||||
typedef mpl::false_ is_view;
|
||||
|
||||
template <typename Sequence>
|
||||
@ -76,7 +76,7 @@ namespace boost { namespace fusion
|
||||
typedef typename detail::deque_keyed_values<Head, Tail...>::type base;
|
||||
typedef mpl::int_<(sizeof ...(Tail) + 1)> size;
|
||||
typedef mpl::int_<size::value> next_up;
|
||||
typedef mpl::int_<((size::value == 0) ? 0 : -1)> next_down;
|
||||
typedef mpl::int_<-1> next_down;
|
||||
typedef mpl::false_ is_view;
|
||||
|
||||
BOOST_FUSION_GPU_ENABLED
|
||||
|
@ -11,9 +11,6 @@
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/container/deque/deque_iterator.hpp>
|
||||
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct deque_tag;
|
||||
@ -29,12 +26,8 @@ namespace boost { namespace fusion
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef typename
|
||||
mpl::if_c<
|
||||
(Sequence::next_down::value == Sequence::next_up::value)
|
||||
, deque_iterator<Sequence, 0>
|
||||
, deque_iterator<Sequence, (Sequence::next_down::value + 1)>
|
||||
>::type
|
||||
typedef
|
||||
deque_iterator<Sequence, (Sequence::next_down::value + 1)>
|
||||
type;
|
||||
|
||||
BOOST_FUSION_GPU_ENABLED
|
||||
|
@ -74,8 +74,7 @@ namespace boost { namespace fusion {
|
||||
typedef typename detail::deque_keyed_values<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, T)>::type base;
|
||||
typedef typename detail::deque_initial_size<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, T)>::type size;
|
||||
typedef mpl::int_<size::value> next_up;
|
||||
typedef mpl::int_<
|
||||
mpl::if_<mpl::equal_to<size, mpl::int_<0> >, mpl::int_<0>, mpl::int_<-1> >::type::value> next_down;
|
||||
typedef mpl::int_<-1> next_down;
|
||||
typedef mpl::false_ is_view;
|
||||
|
||||
#include <boost/fusion/container/deque/detail/cpp03/deque_forward_ctor.hpp>
|
||||
@ -167,7 +166,7 @@ FUSION_HASH endif
|
||||
typedef bidirectional_traversal_tag category;
|
||||
typedef mpl::int_<0> size;
|
||||
typedef mpl::int_<0> next_up;
|
||||
typedef mpl::int_<0> next_down;
|
||||
typedef mpl::int_<-1> next_down;
|
||||
typedef mpl::false_ is_view;
|
||||
|
||||
template <typename Sequence>
|
||||
|
@ -11,9 +11,6 @@
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/container/deque/deque_iterator.hpp>
|
||||
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct deque_tag;
|
||||
@ -29,12 +26,8 @@ namespace boost { namespace fusion
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef typename
|
||||
mpl::if_c<
|
||||
(Sequence::next_down::value == Sequence::next_up::value)
|
||||
, deque_iterator<Sequence, 0>
|
||||
, deque_iterator<Sequence, Sequence::next_up::value>
|
||||
>::type
|
||||
typedef
|
||||
deque_iterator<Sequence, Sequence::next_up::value>
|
||||
type;
|
||||
|
||||
BOOST_FUSION_GPU_ENABLED
|
||||
|
@ -23,6 +23,45 @@
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef back_extended_deque<initial_deque_type, long> extended_type;
|
||||
extended_type extended(initial_deque, 101L);
|
||||
|
||||
BOOST_TEST(size(extended) == 1);
|
||||
BOOST_TEST(extended == make_vector(101L));
|
||||
BOOST_TEST(*begin(extended) == 101L);
|
||||
BOOST_TEST(*prior(end(extended)) == 101L);
|
||||
BOOST_TEST(distance(begin(extended), end(extended)) == 1);
|
||||
}
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
typedef deque<> initial_deque_type;
|
||||
typedef back_extended_deque<initial_deque_type, long> extended_type;
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, long>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, long>));
|
||||
BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
|
||||
}
|
||||
{
|
||||
long l(101L);
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef back_extended_deque<initial_deque_type, long&> extended_type;
|
||||
extended_type extended(initial_deque, l);
|
||||
BOOST_TEST(extended == make_vector(101L));
|
||||
|
||||
long l2(202L);
|
||||
extended_type extended2(initial_deque_type(), l2);
|
||||
|
||||
extended = extended2;
|
||||
|
||||
BOOST_TEST(extended == make_vector(202L));
|
||||
|
||||
BOOST_TEST(l == l2);
|
||||
}
|
||||
|
||||
{
|
||||
typedef deque<int, char> initial_deque_type;
|
||||
initial_deque_type initial_deque(1, 'a');
|
||||
|
@ -23,6 +23,45 @@
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef front_extended_deque<initial_deque_type, int> extended_type;
|
||||
extended_type extended(initial_deque, 1);
|
||||
|
||||
BOOST_TEST(size(extended) == 1);
|
||||
BOOST_TEST(extended == make_vector(1));
|
||||
BOOST_TEST(*begin(extended) == 1);
|
||||
BOOST_TEST(*prior(end(extended)) == 1);
|
||||
BOOST_TEST(distance(begin(extended), end(extended)) == 1);
|
||||
}
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
typedef deque<> initial_deque_type;
|
||||
typedef front_extended_deque<initial_deque_type, int> extended_type;
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>));
|
||||
BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
|
||||
}
|
||||
{
|
||||
int i(1);
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef front_extended_deque<initial_deque_type, int&> extended_type;
|
||||
extended_type extended(initial_deque, i);
|
||||
BOOST_TEST(extended == make_vector(1));
|
||||
|
||||
int i2(2);
|
||||
extended_type extended2(initial_deque_type(), i2);
|
||||
|
||||
extended = extended2;
|
||||
|
||||
BOOST_TEST(extended == make_vector(2));
|
||||
|
||||
BOOST_TEST(i == i2);
|
||||
}
|
||||
|
||||
{
|
||||
typedef deque<char, long> initial_deque_type;
|
||||
initial_deque_type initial_deque('a', 101L);
|
||||
|
Reference in New Issue
Block a user