bug and fix
[email protected] ("Ducky Sherwood")
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi -- I found a bug in gdImageFilledPolygon. In some cases, you can get an odd number of x-intercepts, which means that in the call to gdImageLine gdImageLine (im, im->polyInts[i], y, im->polyInts[i + 1], y, fill_color); the im->polyInts[i+1] will be garbage. This can mess up the drawing of the line. I have attached a test case (bug.c) which shows a horizontal line being drawn where it shouldn't. I have also attached a patch, made with diff -Naur gd.c gd.c.good > horizontalLineBug.patch (I would have reported the bug and patch on flypaper, but I never saw a reply (and yes, I told it my correct email address, and no, I couldn't find it in my spam folder).) -- Ducky Sherwood
bug.c
(text/x-csrc, 851 B)
#include "gd.h"
/* This is a quickie test program to show a bug in gd.
* There is a red line that is drawn across the bottom of
* the image that shouldn't be there.
*
*/
int main(int argc, char *argv[])
{
int white = gdTrueColorAlpha(255, 255, 255, 10);
int red = gdTrueColorAlpha(255, 0, 0, 10);
gdImagePtr im = gdImageCreateTrueColor(256, 256);
gdImageFilledRectangle(im, 0, 0, 256, 256, white);
gdPoint points[4];
points[3].x = 200;
points[3].y = 247;
points[2].x = 248;
points[2].y = 248;
points[1].x = 250;
points[1].y = 255; /* if this is 254, it works */
points[0].x = 256;
points[0].y = 280; /* broken for all y>255? */
// miny = 130
// maxy = 255 or 256
gdImageFilledPolygon(im, points, 4, red);
FILE * pngout = fopen("/tmp/tmp.png", "wb");
gdImagePng(im, pngout);
fclose(pngout);
}
horizontalLineBug.patch
(text/x-patch, 658 B)
--- gd.c 2007-07-18 22:33:12.000000000 -0700
+++ gd.c.good 2007-07-18 22:32:55.000000000 -0700
@@ -3091,6 +3091,16 @@
(float) (y2 - y1) + 0.5 + x1);
}
}
+
+
+ // This is needed because sometimes you can end up with an odd
+ // number of ints...
+ if(1 == ints%2)
+ {
+ im->polyInts[ints] = im->polyInts[ints-1];
+ }
+
+
/*
2.0.26: polygons pretty much always have less than 100 points,
and most of the time they have considerably less. For such trivial
@@ -3106,6 +3116,10 @@
}
im->polyInts[j] = index;
}
+
+
+
+
for (i = 0; (i < (ints)); i += 2)
{
#if 0