Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Feb 6, 2024

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.

@plietar plietar requested a review from giovannic February 6, 2024 19:54
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.
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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
@@           Coverage Diff           @@
##           master     #184   +/-   ##
=======================================
  Coverage   96.25%   96.26%           
=======================================
  Files          36       36           
  Lines        1817     1819    +2     
=======================================
+ Hits         1749     1751    +2     
  Misses         68       68           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@giovannic giovannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks

@plietar plietar changed the base branch from master to dev February 7, 2024 12:16
@plietar plietar merged commit 5c5926d into mrc-ide:dev Feb 7, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants