diff --git a/include/etl/deque.h b/include/etl/deque.h index c3ff33d9..094997b7 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -791,6 +791,8 @@ namespace etl //************************************************************************* reference operator[](size_t index) { + ETL_ASSERT_CHECK_INDEX_OPERATOR(index < current_size, ETL_ERROR(deque_out_of_bounds)); + iterator result(_begin); result += static_cast(index); @@ -803,6 +805,8 @@ namespace etl //************************************************************************* const_reference operator[](size_t index) const { + ETL_ASSERT_CHECK_INDEX_OPERATOR(index < current_size, ETL_ERROR(deque_out_of_bounds)); + iterator result(_begin); result += static_cast(index); @@ -2196,7 +2200,8 @@ namespace etl iterator item = _begin; - do { + do + { ::new (&(*item)) T(*from); ++item; ++from; diff --git a/test/test_deque.cpp b/test/test_deque.cpp index d03580bd..5b4c75ff 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -394,6 +394,14 @@ namespace CHECK_EQUAL(compare_data.at(5), data.at(5)); } + //************************************************************************* + TEST(test_at_out_of_bounds) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data.at(data.size()), etl::deque_out_of_bounds); + } + //************************************************************************* TEST(test_at_const) { @@ -408,6 +416,14 @@ namespace CHECK_EQUAL(compare_data.at(5), data.at(5)); } + //************************************************************************* + TEST(test_at_const_out_of_bounds) + { + const DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data.at(data.size()), etl::deque_out_of_bounds); + } + //************************************************************************* TEST(test_index_operator) { @@ -422,6 +438,14 @@ namespace CHECK_EQUAL(compare_data[5], data[5]); } + //************************************************************************* + TEST(test_index_operator_out_of_bounds) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data[data.size()], etl::deque_out_of_bounds); + } + //************************************************************************* TEST(test_index_operator_const) { @@ -436,6 +460,14 @@ namespace CHECK_EQUAL(compare_data[5], data[5]); } + //************************************************************************* + TEST(test_index_operator_const_out_of_bounds) + { + const DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data[data.size()], etl::deque_out_of_bounds); + } + //************************************************************************* TEST(test_front) {