Merge pull request #2494 from aprilnovak/delete-tally

Correct index check for remove_tally.
This commit is contained in:
Paul Romano 2023-04-26 13:33:40 -05:00 committed by GitHub
commit 3565cbf5d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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