mrc-ide / individual

R Package for individual based epidemiological models
https://mrc-ide.github.io/individual
Other
30 stars 16 forks source link

Check if the schedule is empty before reading it. #184

Closed plietar closed 9 months ago

plietar commented 10 months ago

The Event::should_trigger method uses .begin() on the set of times at which it needs to fire to compare that value with the current tick. However it was missing a check in the case of an empty set. When that happens, begin() returns a pointer to uninitialized memory and we we reading garbage out of it. If that garbage happens to be equal to the current time step, the event would fire spuriously, even though it wasn't meant to.

The fix is straightforward: we just need to check if the set is empty before reading from the set. If it is empty then the event never triggers.

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (877fa6b) 96.25% compared to head (85c9afd) 96.26%. Report is 3 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #184 +/- ## ======================================= Coverage 96.25% 96.26% ======================================= Files 36 36 Lines 1817 1819 +2 ======================================= + Hits 1749 1751 +2 Misses 68 68 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.