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);