Skip to content

gdiplus: Avoid computation overflow and underflow by using hypotf

Bartosz Kosiorek requested to merge gang65/wine:hypot into master

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45123

In gdiplus/graphicspath.c calculating the Pythagorean addition is needed, which is defined as:

a ⊕ b = sqrt(a^2+b^2)

This is hypotenuse, or the length of the longest side of a right-angled triangle, that we know the other 2 sides, a and b. https://en.wikipedia.org/wiki/Pythagorean_addition

By using sqrt(a * a + b * b), for large (or small) a or b, there is a possibility of overflow (underflow), although the result itself is not that big (small) to cause overflow (underflow).

To overcome this problem, there are implementations of hypotenuse that do not use power of 2, and use other methods to calculate the result. To calculate a ⊕ b, you can easily use hypotf(a,b).

https://en.cppreference.com/w/cpp/numeric/math/hypot

Edited by Bartosz Kosiorek

Merge request reports

Loading