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

Fix UBSan error at early startup about converting infinity to int. #1438

Merged
merged 1 commit into from
Jun 17, 2020

Conversation

divVerent
Copy link
Contributor

This happens because during early startup, the FPS value returned by the
stats is zero, and 1 / 0 = inf, and static_cast(inf) is undefined
behavior.

Also, I removed one case as it's dead code (measurements_cnt <= 0 cannot
happen as the function itself increments it), and riddled the timing code
with asserts and comments explaining why each assert is always true.

This happens because during early startup, the FPS value returned by the
stats is zero, and 1 / 0 = inf, and static_cast<int>(inf) is undefined
behavior.

Also, I removed one case as it's dead code (measurements_cnt <= 0 cannot
happen as the function itself increments it), and riddled the timing code
with asserts and comments explaining why each assert is always true.
@tobbi tobbi merged commit 7249298 into SuperTux:master Jun 17, 2020
@divVerent divVerent deleted the divVerent/fps-counter-ub-fix branch June 18, 2020 12:16
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