Correct index check for remove_tally. Refs #2493

This commit is contained in:
April Novak 2023-04-25 15:40:29 -07:00
parent a12480400b
commit 646ef6d322

View file

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