Skip to content

Commit

Permalink
fix memory crash in prob_any_missing (#38)
Browse files Browse the repository at this point in the history
The code fix addresses a memory crash issue in the `prob_any_missing` function. The fix includes adding a condition to check if `maxNumEvents` is less than `totalEvents`. If true, it fills the `probVec` vector with 1.0 and returns it. This prevents the memory crash and ensures proper execution of the function.
  • Loading branch information
m-murphy authored Oct 29, 2024
1 parent 441f898 commit 9090fbd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/prob_any_missing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ std::vector<float> probAnyMissingFunctor::vectorized(
const std::size_t totalEvents = eventProbs.size();

std::vector<float> probVec(maxNumEvents - minNumEvents + 1, 0.0);

if (maxNumEvents < totalEvents) {
std::fill_n(probVec.begin(), maxNumEvents - minNumEvents + 1, 1.0);
return probVec;
}

std::fill_n(probVec.begin(), totalEvents - 1, 1.0);

// Calculate via inclusion-exclusion principle
Expand Down

0 comments on commit 9090fbd

Please sign in to comment.