gdi32: Use 64-bit values when computing ellipses to avoid overflows.

This commit is contained in:
Alexandre Julliard 2012-02-24 15:55:00 +01:00
parent 67a0db3c38
commit c65de04789
2 changed files with 13 additions and 12 deletions

View file

@ -78,11 +78,11 @@ static int ellipse_first_quadrant( int width, int height, POINT *data )
{
const int a = width - 1;
const int b = height - 1;
const int asq = 8 * a * a;
const int bsq = 8 * b * b;
int dx = 4 * b * b * (1 - a);
int dy = 4 * a * a * (1 + (b % 2));
int err = dx + dy + a * a * (b % 2);
const INT64 asq = (INT64)8 * a * a;
const INT64 bsq = (INT64)8 * b * b;
INT64 dx = (INT64)4 * b * b * (1 - a);
INT64 dy = (INT64)4 * a * a * (1 + (b % 2));
INT64 err = dx + dy + a * a * (b % 2);
int pos = 0;
POINT pt;
@ -93,7 +93,7 @@ static int ellipse_first_quadrant( int width, int height, POINT *data )
while (pt.x >= width / 2)
{
int e2 = 2 * err;
INT64 e2 = 2 * err;
data[pos++] = pt;
if (e2 >= dx)
{

View file

@ -754,7 +754,8 @@ HRGN WINAPI CreateRoundRectRgn( INT left, INT top,
{
RGNOBJ * obj;
HRGN hrgn = 0;
int a, b, i, x, y, asq, bsq, dx, dy, err;
int a, b, i, x, y;
INT64 asq, bsq, dx, dy, err;
RECT *rects;
/* Make the dimensions sensible */
@ -788,10 +789,10 @@ HRGN WINAPI CreateRoundRectRgn( INT left, INT top,
a = ellipse_width - 1;
b = ellipse_height - 1;
asq = 8 * a * a;
bsq = 8 * b * b;
dx = 4 * b * b * (1 - a);
dy = 4 * a * a * (1 + (b % 2));
asq = (INT64)8 * a * a;
bsq = (INT64)8 * b * b;
dx = (INT64)4 * b * b * (1 - a);
dy = (INT64)4 * a * a * (1 + (b % 2));
err = dx + dy + a * a * (b % 2);
x = 0;
@ -802,7 +803,7 @@ HRGN WINAPI CreateRoundRectRgn( INT left, INT top,
while (x <= ellipse_width / 2)
{
int e2 = 2 * err;
INT64 e2 = 2 * err;
if (e2 >= dx)
{
x++;