From bc6f9fbd22aadfa3d18edd0c034c127c487965fc Mon Sep 17 00:00:00 2001 From: Georgiy Lebedev Date: Wed, 22 Nov 2023 15:03:54 +0300 Subject: [PATCH] Test: fix undefined behaviour in ListUnitTest The `test_multilinik_round` test scenario of ListUnitTest uses a reference to a `vector` element that is invalidated after a `vector::emplace_back` call. Fix this by calling `vector::emplace_back` after using the referenced element. --- test/ListUnitTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ListUnitTest.cpp b/test/ListUnitTest.cpp index bf4adc28e..12d538c1e 100644 --- a/test/ListUnitTest.cpp +++ b/test/ListUnitTest.cpp @@ -1162,12 +1162,12 @@ void test_multilinik_round() bool red_before = 0 != (r & 1); bool green_before = 0 != (r & 2); bool blue_before = 0 != (r & 4); - objects.emplace_back(id, near, - red_before, green_before, blue_before); expected_insert_near(expected_red, red_before, near.m_Data, id); expected_insert_near(expected_green, green_before, near.m_Data, id); expected_insert_near(expected_blue, blue_before, near.m_Data, id); + + objects.emplace_back(id, near, red_before, green_before, blue_before); }; auto insert_to_list = [&]() {