Ondřej Surý: > Hi Lucas, > > this: https://github.com/libgd/libgd/issues/615 ? > >[...] >
Hi Ondřej, Thanks for the link. It indeed looks related and if I special case 0-sized strings in mscgen, the error goes away (see attached patch). Should I apply this patch to mscgen, or should this be fixed in libgd2? ~Niels
diff --git a/src/gd_out.c b/src/gd_out.c index 64d82b2..34451f9 100644 --- a/src/gd_out.c +++ b/src/gd_out.c @@ -194,6 +194,12 @@ unsigned int gdoTextWidth(struct ADrawTag *ctx, int rect[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; const char *r; + /* Work around https://github.com/libgd/libgd/issues/615 */ + if (string[0] == '\0') + { + return 0; + } + r = gdImageStringFT(NULL, rect, context->pen, @@ -297,6 +303,11 @@ void gdoTextR(struct ADrawTag *ctx, int textWidth; textWidth = gdoTextWidth(ctx, string); + /* Work around https://github.com/libgd/libgd/issues/615 */ + if (textWidth == 0) + { + return; + } /* Range check since gdImageFilledRectangle() takes signed values */ if(x + textWidth <= INT_MAX && y <= INT_MAX)