Avoid out-of-bounds access on index_inelastic_scatter_

This commit is contained in:
Paul Romano 2023-02-06 21:49:43 -06:00
parent 6218becb17
commit 5470ec75b4

View file

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