From 5470ec75b4215faa296bec05a203dcfb9d89d30e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 6 Feb 2023 21:49:43 -0600 Subject: [PATCH] Avoid out-of-bounds access on index_inelastic_scatter_ --- src/physics.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/physics.cpp b/src/physics.cpp index 7cb8040f6..d924b72be 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -705,17 +705,10 @@ void scatter(Particle& p, int i_nuclide) // ======================================================================= // INELASTIC SCATTERING - int j = 0; + int n = nuc->index_inelastic_scatter_.size(); int i = 0; - while (prob < cutoff) { + for (int j = 0; j < n && prob < cutoff; ++j) { i = nuc->index_inelastic_scatter_[j]; - ++j; - - // Check to make sure inelastic scattering reaction sampled - if (i >= nuc->reactions_.size()) { - p.write_restart(); - fatal_error("Did not sample any reaction for nuclide " + nuc->name_); - } // add to cumulative probability prob += nuc->reactions_[i]->xs(micro);