Skip to content

Fix possible division by zero in radius calculation.#750

Merged
tsipinakis merged 1 commit into
dunst-project:masterfrom
MaximeWack:master
Aug 15, 2020
Merged

Fix possible division by zero in radius calculation.#750
tsipinakis merged 1 commit into
dunst-project:masterfrom
MaximeWack:master

Conversation

@MaximeWack
Copy link
Copy Markdown
Contributor

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 == 0 too might be a bit overkill though.

@MaximeWack MaximeWack mentioned this pull request Aug 11, 2020
Comment thread src/draw.c Outdated
// 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (r == 0 || r == w || s == 0 || h == - (w - r) * 2)
if (r == 0 || h + (w - r) * 2 == 0)

Some points:

  • s == 0 is 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@MaximeWack ping? No pressure if you're busy, but I'm waiting for you to update the PR in order to merge this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Thanks for the fix!

@tsipinakis tsipinakis merged commit ca6ce68 into dunst-project:master Aug 15, 2020
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.

[i3-gaps] Transparency issue with rounded corners?

2 participants