Fix possible division by zero in radius calculation.#750
Merged
Conversation
Closed
tsipinakis
reviewed
Aug 11, 2020
| // Integer precision scaler, using 1/4 of int size | ||
| const int s = 2 << (8 * sizeof(int) / 4); | ||
|
|
||
| if (r == 0 || r == w || s == 0 || h == - (w - r) * 2) |
Member
There was a problem hiding this comment.
Suggested change
| if (r == 0 || r == w || s == 0 || h == - (w - r) * 2) | |
| if (r == 0 || h + (w - r) * 2 == 0) |
Some points:
s == 0is indeed overkill, it's a constant after all.- What's the point of
r == w? The final check already checks for a division by 0 in that equation.
And a small readability nitpick, compare everything with 0 to be clear what it's actually checking.
Contributor
Author
There was a problem hiding this comment.
You are absolutely right!
I first thought of r == w then I completed with invalid values for h without remembering to get rid of the first test.
Member
There was a problem hiding this comment.
@MaximeWack ping? No pressure if you're busy, but I'm waiting for you to update the PR in order to merge this.
Contributor
Author
There was a problem hiding this comment.
Oops, sorry, forgot about this ! It's updated now.
Thank you !
Check all possible causes of division by zero in the calculation of the radius.
tsipinakis
approved these changes
Aug 15, 2020
Member
|
Thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Check all possible causes of division by zero in the calculation of the radius.
This fixes #746, and correctly checks for division by zero.
Checking
s == 0too might be a bit overkill though.