From 16392c85288c24b5baaddadfda93fc25970c168f Mon Sep 17 00:00:00 2001 From: Nikolas Date: Fri, 6 Sep 2024 15:03:30 +0200 Subject: [PATCH] Fix size_t underflow in geodesic worldtube evolution --- .../Worldtube/ElementActions/SendToWorldtube.hpp | 4 ++-- .../Worldtube/SingletonActions/ReceiveElementData.hpp | 4 ++-- .../Worldtube/ElementActions/Test_Iterations.cpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/SendToWorldtube.hpp b/src/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/SendToWorldtube.hpp index 129eca3ddee2..6d860b72ee82 100644 --- a/src/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/SendToWorldtube.hpp +++ b/src/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/SendToWorldtube.hpp @@ -164,8 +164,8 @@ struct SendToWorldtube { Parallel::receive_data>( worldtube_component, db::get<::Tags::TimeStepId>(box), std::make_pair(element_id, std::move(Ylm_coefs))); - if (db::get(box) < - db::get(box) - 1) { + if (db::get(box) + 1 < + db::get(box) ) { db::mutate( [](const gsl::not_null current_iteration) { *current_iteration += 1; diff --git a/src/Evolution/Systems/CurvedScalarWave/Worldtube/SingletonActions/ReceiveElementData.hpp b/src/Evolution/Systems/CurvedScalarWave/Worldtube/SingletonActions/ReceiveElementData.hpp index 752f5f49963f..5c228a52cced 100644 --- a/src/Evolution/Systems/CurvedScalarWave/Worldtube/SingletonActions/ReceiveElementData.hpp +++ b/src/Evolution/Systems/CurvedScalarWave/Worldtube/SingletonActions/ReceiveElementData.hpp @@ -128,8 +128,8 @@ struct ReceiveElementData { ylm::ylm_to_stf_0(dt_psi_ylm_l0), std::move(psi_stf_l1), std::move(dt_psi_stf_l1)); inbox.erase(time_step_id); - if (db::get(box) < - db::get(box) - 1) { + if (db::get(box) + 1 < + db::get(box)) { db::mutate( [](const gsl::not_null current_iteration) { *current_iteration += 1; diff --git a/tests/Unit/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/Test_Iterations.cpp b/tests/Unit/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/Test_Iterations.cpp index d1c6644ac485..0c22153666e3 100644 --- a/tests/Unit/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/Test_Iterations.cpp +++ b/tests/Unit/Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions/Test_Iterations.cpp @@ -296,7 +296,7 @@ void test_iterations(const size_t max_iterations) { make_not_null(&runner), element_id)); } - for (size_t current_iteration = 1; current_iteration <= max_iterations - 1; + for (size_t current_iteration = 1; current_iteration + 1 <= max_iterations; ++current_iteration) { CAPTURE(current_iteration); using inbox_tag = Tags::SphericalHarmonicsInbox; @@ -411,6 +411,7 @@ void test_iterations(const size_t max_iterations) { } SPECTRE_TEST_CASE("Unit.CurvedScalarWave.Worldtube.Iterations", "[Unit]") { + test_iterations(0); test_iterations(1); test_iterations(2); test_iterations(5);