summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2016-04-06 17:42:17 +0200
committerKim Woelders <kim@woelders.dk>2016-04-07 20:24:32 +0200
commitc94d83ccab15d5ef02f88d42dce38ed3f0892882 (patch)
tree4fa3b98db7529e5834e31e231ce4904a1e9f59c1
parenta8ca99a2a4ad5015f904b831b712d96b816ef13e (diff)
Fix potential divide-by-zero in imlib_image_draw_ellipse().
Attempting to draw a 2x1 ellipse with e.g. imlib_image_draw_ellipse(x, y, 2, 1) causes a divide-by-zero. It seems happy enough to draw 1x1, 1x2 and 2x2, but not 2x1. Patch by Simon Lees. https://bugs.debian.org/639414
-rw-r--r--src/lib/ellipse.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/ellipse.c b/src/lib/ellipse.c
index cd90268..ddb410b 100644
--- a/src/lib/ellipse.c
+++ b/src/lib/ellipse.c
@@ -71,6 +71,9 @@ __imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
71 if (IN_RANGE(rx, by, clw, clh)) 71 if (IN_RANGE(rx, by, clw, clh))
72 pfunc(color, bp + len); 72 pfunc(color, bp + len);
73 73
74 if (dx < 1)
75 dx = 1;
76
74 dy += b2; 77 dy += b2;
75 yy -= ((dy << 16) / dx); 78 yy -= ((dy << 16) / dx);
76 lx--; 79 lx--;
@@ -123,6 +126,9 @@ __imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
123 if (IN_RANGE(rx, by, clw, clh)) 126 if (IN_RANGE(rx, by, clw, clh))
124 pfunc(color, bp + len); 127 pfunc(color, bp + len);
125 128
129 if (dy < 1)
130 dy = 1;
131
126 dx -= a2; 132 dx -= a2;
127 xx += ((dx << 16) / dy); 133 xx += ((dx << 16) / dy);
128 ty++; 134 ty++;
@@ -222,6 +228,9 @@ __imlib_Ellipse_DrawToData_AA(int xc, int yc, int a, int b, DATA32 color,
222 if (IN_RANGE(rx, by, clw, clh)) 228 if (IN_RANGE(rx, by, clw, clh))
223 pfunc(col1, bp + len); 229 pfunc(col1, bp + len);
224 230
231 if (dx < 1)
232 dx = 1;
233
225 dy += b2; 234 dy += b2;
226 yy -= ((dy << 16) / dx); 235 yy -= ((dy << 16) / dx);
227 lx--; 236 lx--;
@@ -295,6 +304,9 @@ __imlib_Ellipse_DrawToData_AA(int xc, int yc, int a, int b, DATA32 color,
295 if (IN_RANGE(rx, by, clw, clh)) 304 if (IN_RANGE(rx, by, clw, clh))
296 pfunc(col1, bp + len); 305 pfunc(col1, bp + len);
297 306
307 if (dy < 1)
308 dy = 1;
309
298 dx -= a2; 310 dx -= a2;
299 xx += ((dx << 16) / dy); 311 xx += ((dx << 16) / dy);
300 ty++; 312 ty++;
@@ -395,6 +407,9 @@ __imlib_Ellipse_FillToData(int xc, int yc, int a, int b, DATA32 color,
395 if (IN_RANGE(rx, by, clw, clh)) 407 if (IN_RANGE(rx, by, clw, clh))
396 pfunc(color, bp + len); 408 pfunc(color, bp + len);
397 409
410 if (dx < 1)
411 dx = 1;
412
398 dy += b2; 413 dy += b2;
399 yy -= ((dy << 16) / dx); 414 yy -= ((dy << 16) / dx);
400 lx--; 415 lx--;
@@ -453,6 +468,9 @@ __imlib_Ellipse_FillToData(int xc, int yc, int a, int b, DATA32 color,
453 if (((unsigned)by < (unsigned)clh) && (len > 0)) 468 if (((unsigned)by < (unsigned)clh) && (len > 0))
454 sfunc(color, bpp, len); 469 sfunc(color, bpp, len);
455 470
471 if (dy < 1)
472 dy = 1;
473
456 dx -= a2; 474 dx -= a2;
457 xx += ((dx << 16) / dy); 475 xx += ((dx << 16) / dy);
458 ty++; 476 ty++;
@@ -556,6 +574,9 @@ __imlib_Ellipse_FillToData_AA(int xc, int yc, int a, int b, DATA32 color,
556 if (IN_RANGE(rx, by, clw, clh)) 574 if (IN_RANGE(rx, by, clw, clh))
557 pfunc(col1, bp + len); 575 pfunc(col1, bp + len);
558 576
577 if (dx < 1)
578 dx = 1;
579
559 dy += b2; 580 dy += b2;
560 yy -= ((dy << 16) / dx); 581 yy -= ((dy << 16) / dx);
561 lx--; 582 lx--;
@@ -629,6 +650,9 @@ __imlib_Ellipse_FillToData_AA(int xc, int yc, int a, int b, DATA32 color,
629 if (IN_RANGE(rx, by, clw, clh)) 650 if (IN_RANGE(rx, by, clw, clh))
630 pfunc(col1, bp + len); 651 pfunc(col1, bp + len);
631 652
653 if (dy < 1)
654 dy = 1;
655
632 dx -= a2; 656 dx -= a2;
633 xx += ((dx << 16) / dy); 657 xx += ((dx << 16) / dy);
634 ty++; 658 ty++;