From 646ef6d322b87ea02becced3e80fa2f77c8edf5c Mon Sep 17 00:00:00 2001 From: April Novak Date: Tue, 25 Apr 2023 15:40:29 -0700 Subject: [PATCH] Correct index check for remove_tally. Refs #2493 --- src/tallies/tally.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 8056b2574..0610c8cf1 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -1280,12 +1280,11 @@ extern "C" size_t tallies_size() extern "C" int openmc_remove_tally(int32_t index) { // check that id is in the map - if (index < 0 || index > model::tallies.size()) { + if (index < 0 || index >= model::tallies.size()) { + set_errmsg("Index in tallies array is out of bounds."); return OPENMC_E_OUT_OF_BOUNDS; } - // grab tally so it's ID can be obtained to remove the (ID,index) pair from - // tally_map - auto& tally = model::tallies[index]; + // delete the tally via iterator pointing to correct position // this calls the Tally destructor, removing the tally from the map as well model::tallies.erase(model::tallies.begin() + index);