diff --git a/include/etl/vector.h b/include/etl/vector.h index 43eff53c..d11985d2 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -744,8 +744,8 @@ namespace etl etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); ETL_ADD_DEBUG_COUNT(construct_old_n) - // Copy old. - etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); + // Copy old. + std::copy_backward(p_buffer + insert_begin, p_buffer + insert_begin + copy_old_n, p_buffer + insert_end + copy_old_n); // Construct new. etl::uninitialized_fill_n(p_end, construct_new_n, value); @@ -801,15 +801,15 @@ namespace etl etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); ETL_ADD_DEBUG_COUNT(construct_old_n) - // Copy old. - etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); + // Copy old. + std::copy_backward(p_buffer + insert_begin, p_buffer + insert_begin + copy_old_n, p_buffer + insert_end + copy_old_n); // Construct new. etl::uninitialized_copy_n(first + copy_new_n, construct_new_n, p_end); ETL_ADD_DEBUG_COUNT(construct_new_n) - // Copy new. - etl::copy_n(first, copy_new_n, p_buffer + insert_begin); + // Copy new. + etl::copy_n(first, copy_new_n, p_buffer + insert_begin); p_end += count; } diff --git a/include/etl/version.h b/include/etl/version.h index ef318fff..c3ed749f 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 8 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) diff --git a/support/Release notes.txt b/support/Release notes.txt index a9ad0685..d9fe8a5b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.8.1 +Fixed bug for certain inserts in etl::vector + =============================================================================== 14.8.0 Added etl::callback_service diff --git a/test/data.h b/test/data.h index 14b5f47c..f6b59b7a 100644 --- a/test/data.h +++ b/test/data.h @@ -53,6 +53,10 @@ public: { } + virtual ~TestDataDC() + { + } + bool operator < (const TestDataDC& other) const { return value < other.value; @@ -109,6 +113,10 @@ public: index(index_) {} + virtual ~TestDataNDC() + { + } + bool operator < (const TestDataNDC& other) const { return value < other.value; @@ -174,6 +182,10 @@ public: other.valid = false; } + virtual ~TestDataM() + { + } + TestDataM& operator =(TestDataM&& other) { value = other.value; diff --git a/test/test_vector.cpp b/test/test_vector.cpp index d87f83de..a2dbb213 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -1036,5 +1036,70 @@ namespace CHECK(!is_equal); } + + //************************************************************************* + TEST(test_insert_bug) + { + struct S + { + virtual ~S() + { + + } + + S(int i): i(i){} + + int i; + }; + + const S raw[6] = { 1, 2, 3, 4, 5, 6 }; + + etl::vector dest(etl::begin(raw), etl::end(raw)); + etl::vector src((size_t) 2, S(8)); + + dest.insert(dest.begin(), src.begin(), src.end()); + + CHECK(dest.size() == 8); + CHECK_EQUAL(src[0].i, dest[0].i); + CHECK_EQUAL(src[1].i, dest[1].i); + CHECK_EQUAL(raw[0].i, dest[2].i); + CHECK_EQUAL(raw[1].i, dest[3].i); + CHECK_EQUAL(raw[2].i, dest[4].i); + CHECK_EQUAL(raw[3].i, dest[5].i); + CHECK_EQUAL(raw[4].i, dest[6].i); + CHECK_EQUAL(raw[5].i, dest[7].i); + } + + //************************************************************************* + TEST(test_insert_n_bug) + { + struct S + { + virtual ~S() + { + + } + + S(int i): i(i){} + + int i; + }; + + const S raw[6] = { 1, 2, 3, 4, 5, 6 }; + + etl::vector dest(etl::begin(raw), etl::end(raw)); + + dest.insert(dest.begin(), 2, S(8)); + + CHECK(dest.size() == 8); + CHECK_EQUAL(8, dest[0].i); + CHECK_EQUAL(8, dest[1].i); + CHECK_EQUAL(raw[0].i, dest[2].i); + CHECK_EQUAL(raw[1].i, dest[3].i); + CHECK_EQUAL(raw[2].i, dest[4].i); + CHECK_EQUAL(raw[3].i, dest[5].i); + CHECK_EQUAL(raw[4].i, dest[6].i); + CHECK_EQUAL(raw[5].i, dest[7].i); + } }; }