gd_error:
  108|    234|void gd_error(const char *format, ...) {
  109|    234|	va_list args;
  110|       |
  111|    234|	va_start(args, format);
  112|    234|	_gd_error_ex(GD_WARNING, format, args);
  ------------------
  |  |   38|    234|#define GD_WARNING LOG_WARNING
  ------------------
  113|       |	va_end(args);
  114|    234|}
gd_error_ex:
  115|    140|void gd_error_ex(int priority, const char *format, ...) {
  116|    140|	va_list args;
  117|       |
  118|    140|	va_start(args, format);
  119|    140|	_gd_error_ex(priority, format, args);
  120|       |	va_end(args);
  121|    140|}
gdImageCreateTrueColor:
  281|    476|BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor(int sx, int sy) {
  282|    476|	int i;
  283|    476|	gdImagePtr im;
  284|       |
  285|    476|	if (overflow2(sx, sy)) {
  ------------------
  |  Branch (285:6): [True: 0, False: 476]
  ------------------
  286|      0|		return NULL;
  287|      0|	}
  288|    476|	if (overflow2(sizeof(int *), sy)) {
  ------------------
  |  Branch (288:6): [True: 10, False: 466]
  ------------------
  289|     10|		return 0;
  290|     10|	}
  291|    466|	if (overflow2(sizeof(int), sx)) {
  ------------------
  |  Branch (291:6): [True: 0, False: 466]
  ------------------
  292|      0|		return NULL;
  293|      0|	}
  294|       |
  295|    466|	im = (gdImage *)gdMalloc(sizeof(gdImage));
  296|    466|	if (!im) {
  ------------------
  |  Branch (296:6): [True: 0, False: 466]
  ------------------
  297|      0|		return 0;
  298|      0|	}
  299|    466|	memset(im, 0, sizeof(gdImage));
  300|       |
  301|    466|	im->tpixels = (int **)gdMalloc(sizeof(int *) * sy);
  302|    466|	if (!im->tpixels) {
  ------------------
  |  Branch (302:6): [True: 0, False: 466]
  ------------------
  303|      0|		gdFree(im);
  304|      0|		return 0;
  305|      0|	}
  306|    466|	im->polyInts = 0;
  307|    466|	im->polyAllocated = 0;
  308|    466|	im->brush = 0;
  309|    466|	im->tile = 0;
  310|    466|	im->style = 0;
  311|  55.0k|	for (i = 0; (i < sy); i++) {
  ------------------
  |  Branch (311:14): [True: 54.6k, False: 466]
  ------------------
  312|  54.6k|		im->tpixels[i] = (int *)gdCalloc(sx, sizeof(int));
  313|  54.6k|		if (!im->tpixels[i]) {
  ------------------
  |  Branch (313:7): [True: 0, False: 54.6k]
  ------------------
  314|       |			/* 2.0.34 */
  315|      0|			i--;
  316|      0|			while (i >= 0) {
  ------------------
  |  Branch (316:11): [True: 0, False: 0]
  ------------------
  317|      0|				gdFree(im->tpixels[i]);
  318|      0|				i--;
  319|      0|			}
  320|      0|			gdFree(im->tpixels);
  321|      0|			gdFree(im);
  322|      0|			return 0;
  323|      0|		}
  324|  54.6k|	}
  325|    466|	im->sx = sx;
  326|    466|	im->sy = sy;
  327|    466|	im->transparent = (-1);
  328|    466|	im->interlace = 0;
  329|    466|	im->trueColor = 1;
  330|       |	/* 2.0.2: alpha blending is now on by default, and saving of alpha is
  331|       |	   off by default. This allows font antialiasing to work as expected
  332|       |	   on the first try in JPEGs -- quite important -- and also allows
  333|       |	   for smaller PNGs when saving of alpha channel is not really
  334|       |	   desired, which it usually isn't! */
  335|    466|	im->saveAlphaFlag = 0;
  336|    466|	im->alphaBlendingFlag = 1;
  337|    466|	im->thick = 1;
  338|    466|	im->AA = 0;
  339|    466|	im->cx1 = 0;
  340|    466|	im->cy1 = 0;
  341|    466|	im->cx2 = im->sx - 1;
  342|    466|	im->cy2 = im->sy - 1;
  343|    466|	im->res_x = GD_RESOLUTION;
  ------------------
  |  | 2196|    466|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  344|    466|	im->res_y = GD_RESOLUTION;
  ------------------
  |  | 2196|    466|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  345|       |	im->interpolation = NULL;
  346|    466|	im->interpolation_id = GD_BILINEAR_FIXED;
  347|    466|	return im;
  348|    466|}
gdImageDestroy:
  378|    466|BGD_DECLARE(void) gdImageDestroy(gdImagePtr im) {
  379|    466|	int i;
  380|    466|	if (im->pixels) {
  ------------------
  |  Branch (380:6): [True: 0, False: 466]
  ------------------
  381|      0|		for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (381:15): [True: 0, False: 0]
  ------------------
  382|      0|			gdFree(im->pixels[i]);
  383|      0|		}
  384|      0|		gdFree(im->pixels);
  385|      0|	}
  386|    466|	if (im->tpixels) {
  ------------------
  |  Branch (386:6): [True: 466, False: 0]
  ------------------
  387|  55.0k|		for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (387:15): [True: 54.6k, False: 466]
  ------------------
  388|  54.6k|			gdFree(im->tpixels[i]);
  389|  54.6k|		}
  390|    466|		gdFree(im->tpixels);
  391|    466|	}
  392|    466|	if (im->polyInts) {
  ------------------
  |  Branch (392:6): [True: 0, False: 466]
  ------------------
  393|      0|		gdFree(im->polyInts);
  394|      0|	}
  395|    466|	if (im->style) {
  ------------------
  |  Branch (395:6): [True: 0, False: 466]
  ------------------
  396|      0|		gdFree(im->style);
  397|      0|	}
  398|    466|	gdFree(im);
  399|    466|}
gdImageAlphaBlending:
 4230|    348|BGD_DECLARE(void) gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg) {
 4231|    348|	im->alphaBlendingFlag = alphaBlendingArg;
 4232|    348|}
gdImageSaveAlpha:
 4243|    348|BGD_DECLARE(void) gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg) {
 4244|    348|	im->saveAlphaFlag = saveAlphaArg;
 4245|    348|}
gd.c:_gd_error_ex:
  102|    374|static void _gd_error_ex(int priority, const char *format, va_list args) {
  103|    374|	if (gd_error_method) {
  ------------------
  |  Branch (103:6): [True: 374, False: 0]
  ------------------
  104|    374|		gd_error_method(priority, format, args);
  105|    374|	}
  106|    374|}
gd.c:gd_stderr_error:
   78|    374|static void gd_stderr_error(int priority, const char *format, va_list args) {
   79|    374|	switch (priority) {
  ------------------
  |  Branch (79:10): [True: 374, False: 0]
  ------------------
   80|      0|	case GD_ERROR:
  ------------------
  |  |   37|      0|#define GD_ERROR LOG_ERR
  ------------------
  |  Branch (80:2): [True: 0, False: 374]
  ------------------
   81|      0|		fputs("GD Error: ", stderr);
   82|      0|		break;
   83|    374|	case GD_WARNING:
  ------------------
  |  |   38|    374|#define GD_WARNING LOG_WARNING
  ------------------
  |  Branch (83:2): [True: 374, False: 0]
  ------------------
   84|    374|		fputs("GD Warning: ", stderr);
   85|    374|		break;
   86|      0|	case GD_NOTICE:
  ------------------
  |  |   39|      0|#define GD_NOTICE LOG_NOTICE
  ------------------
  |  Branch (86:2): [True: 0, False: 374]
  ------------------
   87|      0|		fputs("GD Notice: ", stderr);
   88|      0|		break;
   89|      0|	case GD_INFO:
  ------------------
  |  |   40|      0|#define GD_INFO LOG_INFO
  ------------------
  |  Branch (89:2): [True: 0, False: 374]
  ------------------
   90|      0|		fputs("GD Info: ", stderr);
   91|      0|		break;
   92|      0|	case GD_DEBUG:
  ------------------
  |  |   41|      0|#define GD_DEBUG LOG_DEBUG
  ------------------
  |  Branch (92:2): [True: 0, False: 374]
  ------------------
   93|      0|		fputs("GD Debug: ", stderr);
   94|      0|		break;
   95|    374|	}
   96|    374|	vfprintf(stderr, format, args);
   97|       |	fflush(stderr);
   98|    374|}

gdGetC:
   49|  1.15M|int gdGetC(gdIOCtx *ctx) { return ((ctx->getC)(ctx)); }
gdGetBuf:
  181|   642k|int gdGetBuf(void *buf, int size, gdIOCtx *ctx) {
  182|   642k|	return (ctx->getBuf)(ctx, buf, size);
  183|   642k|}
gdTell:
  191|    377|long gdTell(gdIOCtx *ctx) {
  192|    377|	IO_DBG(printf("Telling...\n"));
  193|    377|	return ((ctx->tell)(ctx));
  194|      0|	IO_DBG(printf("told.\n"));
  195|      0|}

gdNewDynamicCtxEx:
   79|    890|gdNewDynamicCtxEx(int initialSize, void *data, int freeOKFlag) {
   80|    890|	dpIOCtx *ctx;
   81|    890|	dynamicPtr *dp;
   82|       |
   83|    890|	ctx = (dpIOCtx *)gdMalloc(sizeof(dpIOCtx));
   84|    890|	if (ctx == NULL) {
  ------------------
  |  Branch (84:6): [True: 0, False: 890]
  ------------------
   85|      0|		return NULL;
   86|      0|	}
   87|       |
   88|    890|	dp = newDynamic(initialSize, data, freeOKFlag);
   89|    890|	if (!dp) {
  ------------------
  |  Branch (89:6): [True: 0, False: 890]
  ------------------
   90|      0|		gdFree(ctx);
   91|      0|		return NULL;
   92|    890|	};
   93|       |
   94|    890|	ctx->dp = dp;
   95|       |
   96|    890|	ctx->ctx.getC = dynamicGetchar;
   97|    890|	ctx->ctx.putC = dynamicPutchar;
   98|       |
   99|    890|	ctx->ctx.getBuf = dynamicGetbuf;
  100|    890|	ctx->ctx.putBuf = dynamicPutbuf;
  101|       |
  102|    890|	ctx->ctx.seek = dynamicSeek;
  103|    890|	ctx->ctx.tell = dynamicTell;
  104|       |
  105|    890|	ctx->ctx.gd_free = gdFreeDynamicCtx;
  106|       |
  107|    890|	return (gdIOCtx *)ctx;
  108|    890|}
gd_io_dp.c:gdFreeDynamicCtx:
  142|    890|static void gdFreeDynamicCtx(gdIOCtxPtr ctx) {
  143|    890|	dynamicPtr *dp;
  144|    890|	dpIOCtx *dctx;
  145|       |
  146|    890|	dctx = (dpIOCtx *)ctx;
  147|    890|	dp = dctx->dp;
  148|       |
  149|    890|	gdFree(ctx);
  150|       |
  151|       |	/* clean up the data block and return it */
  152|       |	/* 2.0.21: never free memory we don't own */
  153|    890|	if ((dp->data != NULL) && (dp->freeOK)) {
  ------------------
  |  Branch (153:6): [True: 890, False: 0]
  |  Branch (153:28): [True: 0, False: 890]
  ------------------
  154|      0|		gdFree(dp->data);
  155|      0|		dp->data = NULL;
  156|      0|	}
  157|       |
  158|    890|	dp->realSize = 0;
  159|    890|	dp->logicalSize = 0;
  160|       |
  161|    890|	gdFree(dp);
  162|    890|}
gd_io_dp.c:dynamicTell:
  164|    377|static long dynamicTell(gdIOCtxPtr ctx) {
  165|    377|	dpIOCtx *dctx;
  166|       |
  167|    377|	dctx = (dpIOCtx *)ctx;
  168|    377|	return (dctx->dp->pos);
  169|    377|}
gd_io_dp.c:newDynamic:
  217|    890|static dynamicPtr *newDynamic(int initialSize, void *data, int freeOKFlag) {
  218|    890|	dynamicPtr *dp;
  219|       |
  220|    890|	dp = (dynamicPtr *)gdMalloc(sizeof(dynamicPtr));
  221|    890|	if (dp == NULL) {
  ------------------
  |  Branch (221:6): [True: 0, False: 890]
  ------------------
  222|      0|		return NULL;
  223|      0|	}
  224|       |
  225|    890|	if (!allocDynamic(dp, initialSize, data)) {
  ------------------
  |  Branch (225:6): [True: 0, False: 890]
  ------------------
  226|      0|		gdFree(dp);
  227|      0|		return NULL;
  228|      0|	}
  229|       |
  230|    890|	dp->pos = 0;
  231|    890|	dp->freeOK = freeOKFlag;
  232|       |
  233|    890|	return dp;
  234|    890|}
gd_io_dp.c:allocDynamic:
  313|    890|static int allocDynamic(dynamicPtr *dp, int initialSize, void *data) {
  314|    890|	if (data == NULL) {
  ------------------
  |  Branch (314:6): [True: 0, False: 890]
  ------------------
  315|      0|		dp->logicalSize = 0;
  316|      0|		dp->dataGood = FALSE;
  ------------------
  |  |   29|      0|#define FALSE 0
  ------------------
  317|      0|		dp->data = gdMalloc(initialSize);
  318|    890|	} else {
  319|    890|		dp->logicalSize = initialSize;
  320|    890|		dp->dataGood = TRUE;
  ------------------
  |  |   28|    890|#define TRUE 1
  ------------------
  321|    890|		dp->data = data;
  322|    890|	}
  323|       |
  324|    890|	if (dp->data != NULL) {
  ------------------
  |  Branch (324:6): [True: 890, False: 0]
  ------------------
  325|    890|		dp->realSize = initialSize;
  326|    890|		dp->dataGood = TRUE;
  ------------------
  |  |   28|    890|#define TRUE 1
  ------------------
  327|    890|		dp->pos = 0;
  328|    890|		return TRUE;
  ------------------
  |  |   28|    890|#define TRUE 1
  ------------------
  329|    890|	} else {
  330|      0|		dp->realSize = 0;
  331|      0|		return FALSE;
  ------------------
  |  |   29|      0|#define FALSE 0
  ------------------
  332|      0|	}
  333|    890|}
gd_io_dp.c:dynamicGetbuf:
  260|  1.80M|static int dynamicGetbuf(gdIOCtxPtr ctx, void *buf, int len) {
  261|  1.80M|	int rlen, remain;
  262|  1.80M|	dpIOCtxPtr dctx;
  263|  1.80M|	dynamicPtr *dp;
  264|       |
  265|  1.80M|	dctx = (dpIOCtxPtr)ctx;
  266|  1.80M|	dp = dctx->dp;
  267|       |
  268|  1.80M|	if (dp->pos < 0 || dp->pos >= dp->realSize) {
  ------------------
  |  Branch (268:6): [True: 0, False: 1.80M]
  |  Branch (268:21): [True: 59.9k, False: 1.74M]
  ------------------
  269|  59.9k|		return 0;
  270|  59.9k|	}
  271|       |
  272|  1.74M|	remain = dp->logicalSize - dp->pos;
  273|  1.74M|	if (remain >= len) {
  ------------------
  |  Branch (273:6): [True: 1.74M, False: 47]
  ------------------
  274|  1.74M|		rlen = len;
  275|  1.74M|	} else {
  276|     47|		if (remain <= 0) {
  ------------------
  |  Branch (276:7): [True: 0, False: 47]
  ------------------
  277|      0|			return 0;
  278|      0|		}
  279|       |
  280|     47|		rlen = remain;
  281|     47|	}
  282|       |
  283|  1.74M|	if (dp->pos + rlen > dp->realSize) {
  ------------------
  |  Branch (283:6): [True: 0, False: 1.74M]
  ------------------
  284|      0|		rlen = dp->realSize - dp->pos;
  285|      0|	}
  286|       |
  287|  1.74M|	if (rlen < 0) {
  ------------------
  |  Branch (287:6): [True: 0, False: 1.74M]
  ------------------
  288|      0|		return 0;
  289|      0|	}
  290|       |
  291|  1.74M|	memcpy(buf, (void *)((char *)dp->data + dp->pos), rlen);
  292|  1.74M|	dp->pos += rlen;
  293|       |
  294|  1.74M|	return rlen;
  295|  1.74M|}
gd_io_dp.c:dynamicGetchar:
  297|  1.15M|static int dynamicGetchar(gdIOCtxPtr ctx) {
  298|  1.15M|	unsigned char b;
  299|  1.15M|	int rv;
  300|       |
  301|  1.15M|	rv = dynamicGetbuf(ctx, &b, 1);
  302|       |
  303|  1.15M|	if (rv != 1) {
  ------------------
  |  Branch (303:6): [True: 408, False: 1.15M]
  ------------------
  304|    408|		return EOF;
  305|  1.15M|	} else {
  306|  1.15M|		return b; /* (b & 0xff); */
  307|  1.15M|	}
  308|  1.15M|}

overflow2:
   21|  3.62k|int overflow2(int a, int b) {
   22|  3.62k|	if (a <= 0 || b <= 0) {
  ------------------
  |  Branch (22:6): [True: 0, False: 3.62k]
  |  Branch (22:16): [True: 0, False: 3.62k]
  ------------------
   23|      0|		gd_error_ex(GD_WARNING,
  ------------------
  |  |   38|      0|#define GD_WARNING LOG_WARNING
  ------------------
   24|      0|					"one parameter to a memory allocation multiplication is "
   25|      0|					"negative or zero, failing operation gracefully\n");
   26|      0|		return 1;
   27|      0|	}
   28|  3.62k|	if (a > 100000 / b) {
  ------------------
  |  Branch (28:6): [True: 52, False: 3.57k]
  ------------------
   29|     52|		gd_error_ex(GD_WARNING,
  ------------------
  |  |   38|     52|#define GD_WARNING LOG_WARNING
  ------------------
   30|     52|					"product of memory allocation multiplication would exceed "
   31|     52|					"100000, failing operation gracefully\n");
   32|     52|		return 1;
   33|     52|	}
   34|  3.57k|	return 0;
   35|  3.62k|}

gdImageCreateFromTgaPtr:
   56|    890|BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data) {
   57|    890|	gdImagePtr im;
   58|    890|	gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
   59|    890|	if (in == NULL)
  ------------------
  |  Branch (59:6): [True: 0, False: 890]
  ------------------
   60|      0|		return NULL;
   61|    890|	im = gdImageCreateFromTgaCtx(in);
   62|    890|	in->gd_free(in);
   63|    890|	return im;
   64|    890|}
gdImageCreateFromTgaCtx:
   74|    890|BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx *ctx) {
   75|    890|	int bitmap_caret = 0;
   76|    890|	oTga *tga = NULL;
   77|    890|	volatile gdImagePtr image = NULL;
   78|    890|	int x = 0;
   79|    890|	int y = 0;
   80|       |
   81|    890|	tga = (oTga *)gdMalloc(sizeof(oTga));
   82|    890|	if (!tga) {
  ------------------
  |  Branch (82:6): [True: 0, False: 890]
  ------------------
   83|      0|		return NULL;
   84|      0|	}
   85|       |
   86|    890|	tga->bitmap = NULL;
   87|    890|	tga->colormap = NULL;
   88|    890|	tga->ident = NULL;
   89|    890|	tga->has_alpha = 0;
   90|       |
   91|    890|	if (read_header_tga(ctx, tga) < 0) {
  ------------------
  |  Branch (91:6): [True: 123, False: 767]
  ------------------
   92|    123|		free_tga(tga);
   93|    123|		return NULL;
   94|    123|	}
   95|       |
   96|    767|	if (read_image_tga(ctx, tga) < 0) {
  ------------------
  |  Branch (96:6): [True: 291, False: 476]
  ------------------
   97|    291|		free_tga(tga);
   98|    291|		return NULL;
   99|    291|	}
  100|       |
  101|    476|	image = gdImageCreateTrueColor((int)tga->width, (int)tga->height);
  102|       |
  103|    476|	if (image == 0) {
  ------------------
  |  Branch (103:6): [True: 10, False: 466]
  ------------------
  104|     10|		free_tga(tga);
  105|     10|		return NULL;
  106|     10|	}
  107|       |
  108|       |	/*!	\brief Populate GD image object
  109|       |	 *  Copy the pixel data from our tga bitmap buffer into the GD image
  110|       |	 *  Disable blending and save the alpha channel per default
  111|       |	 */
  112|    466|	if (tga->has_alpha) {
  ------------------
  |  Branch (112:6): [True: 348, False: 118]
  ------------------
  113|    348|		gdImageAlphaBlending(image, 0);
  114|    348|		gdImageSaveAlpha(image, 1);
  115|    348|	}
  116|       |
  117|  55.0k|	for (y = 0; y < tga->height; y++) {
  ------------------
  |  Branch (117:14): [True: 54.6k, False: 466]
  ------------------
  118|  54.6k|		register int *tpix = image->tpixels[y];
  119|   230k|		for (x = 0; x < tga->width; x++, tpix++) {
  ------------------
  |  Branch (119:15): [True: 176k, False: 54.6k]
  ------------------
  120|   176k|			*tpix = tga->bitmap[bitmap_caret++];
  121|   176k|		}
  122|  54.6k|	}
  123|       |
  124|    466|	if (tga->flipv && tga->fliph) {
  ------------------
  |  Branch (124:6): [True: 139, False: 327]
  |  Branch (124:20): [True: 113, False: 26]
  ------------------
  125|    113|		gdImageFlipBoth(image);
  126|    353|	} else if (tga->flipv) {
  ------------------
  |  Branch (126:13): [True: 26, False: 327]
  ------------------
  127|     26|		gdImageFlipVertical(image);
  128|    327|	} else if (tga->fliph) {
  ------------------
  |  Branch (128:13): [True: 320, False: 7]
  ------------------
  129|    320|		gdImageFlipHorizontal(image);
  130|    320|	}
  131|       |
  132|    466|	free_tga(tga);
  133|       |
  134|    466|	return image;
  135|    476|}
read_header_tga:
  142|    890|int read_header_tga(gdIOCtx *ctx, oTga *tga) {
  143|       |
  144|    890|	unsigned char header[18];
  145|       |
  146|    890|	if (gdGetBuf(header, sizeof(header), ctx) < 18) {
  ------------------
  |  Branch (146:6): [True: 11, False: 879]
  ------------------
  147|     11|		gd_error("fail to read header");
  148|     11|		return -1;
  149|     11|	}
  150|       |
  151|    879|	tga->identsize = header[0];
  152|    879|	tga->colormaptype = header[1];
  153|    879|	tga->imagetype = header[2];
  154|    879|	tga->colormapstart = header[3] + (header[4] << 8);
  155|    879|	tga->colormaplength = header[5] + (header[6] << 8);
  156|    879|	tga->colormapbits = header[7];
  157|    879|	tga->xstart = header[8] + (header[9] << 8);
  158|    879|	tga->ystart = header[10] + (header[11] << 8);
  159|    879|	tga->width = header[12] + (header[13] << 8);
  160|    879|	tga->height = header[14] + (header[15] << 8);
  161|    879|	tga->bits = header[16];
  162|    879|	tga->alphabits = header[17] & 0x0f;
  163|    879|	tga->fliph = (header[17] & 0x10) ? 1 : 0;
  ------------------
  |  Branch (163:15): [True: 628, False: 251]
  ------------------
  164|    879|	tga->flipv = (header[17] & 0x20) ? 0 : 1;
  ------------------
  |  Branch (164:15): [True: 479, False: 400]
  ------------------
  165|    879|	tga->has_alpha = 0;
  166|       |
  167|       |#if DEBUG
  168|       |	printf("format bps: %i\n", tga->bits);
  169|       |	printf("flip h/v: %i / %i\n", tga->fliph, tga->flipv);
  170|       |	printf("alpha: %i\n", tga->alphabits);
  171|       |	printf("wxh: %i %i\n", tga->width, tga->height);
  172|       |#endif
  173|       |
  174|    879|	if (tga->width <= 0 || tga->height <= 0) {
  ------------------
  |  Branch (174:6): [True: 4, False: 875]
  |  Branch (174:25): [True: 1, False: 874]
  ------------------
  175|      5|		gd_error("gd-tga: invalid image dimensions\n");
  176|      5|		return -1;
  177|      5|	}
  178|       |
  179|    874|	if (tga->colormaptype > 1) {
  ------------------
  |  Branch (179:6): [True: 21, False: 853]
  ------------------
  180|     21|		gd_error_ex(GD_WARNING, "gd-tga: unsupported color map type %u\n",
  ------------------
  |  |   38|     21|#define GD_WARNING LOG_WARNING
  ------------------
  181|     21|					tga->colormaptype);
  182|     21|		return -1;
  183|     21|	}
  184|       |
  185|    853|	switch (tga->imagetype) {
  186|     44|	case TGA_TYPE_INDEXED:
  ------------------
  |  |   36|     44|#define TGA_TYPE_INDEXED 1
  ------------------
  |  Branch (186:2): [True: 44, False: 809]
  ------------------
  187|    111|	case TGA_TYPE_INDEXED_RLE:
  ------------------
  |  |   39|    111|#define TGA_TYPE_INDEXED_RLE 9
  ------------------
  |  Branch (187:2): [True: 67, False: 786]
  ------------------
  188|    111|		if (tga->colormaptype != 1 || tga->bits != TGA_BPP_8 ||
  ------------------
  |  |   45|    220|#define TGA_BPP_8 8
  ------------------
  |  Branch (188:7): [True: 2, False: 109]
  |  Branch (188:33): [True: 9, False: 100]
  ------------------
  189|    100|			!(tga->colormapbits == 15 || tga->colormapbits == 16 ||
  ------------------
  |  Branch (189:6): [True: 54, False: 46]
  |  Branch (189:33): [True: 3, False: 43]
  ------------------
  190|     43|			  tga->colormapbits == 24 || tga->colormapbits == 32)) {
  ------------------
  |  Branch (190:6): [True: 2, False: 41]
  |  Branch (190:33): [True: 20, False: 21]
  ------------------
  191|     32|			gd_error_ex(GD_WARNING, "gd-tga: unsupported color mapped image\n");
  ------------------
  |  |   38|     32|#define GD_WARNING LOG_WARNING
  ------------------
  192|     32|			return -1;
  193|     32|		}
  194|     79|		break;
  195|       |
  196|    141|	case TGA_TYPE_RGB:
  ------------------
  |  |   37|    141|#define TGA_TYPE_RGB 2
  ------------------
  |  Branch (196:2): [True: 141, False: 712]
  ------------------
  197|    665|	case TGA_TYPE_RGB_RLE:
  ------------------
  |  |   40|    665|#define TGA_TYPE_RGB_RLE 10
  ------------------
  |  Branch (197:2): [True: 524, False: 329]
  ------------------
  198|    665|		if (!(tga->bits == TGA_BPP_16 || tga->bits == TGA_BPP_24 ||
  ------------------
  |  |   46|  1.33k|#define TGA_BPP_16 16
  ------------------
              		if (!(tga->bits == TGA_BPP_16 || tga->bits == TGA_BPP_24 ||
  ------------------
  |  |   47|  1.19k|#define TGA_BPP_24 24
  ------------------
  |  Branch (198:9): [True: 135, False: 530]
  |  Branch (198:36): [True: 185, False: 345]
  ------------------
  199|    345|			  (tga->bits == TGA_BPP_32 && tga->alphabits == 8))) {
  ------------------
  |  |   48|    690|#define TGA_BPP_32 32
  ------------------
  |  Branch (199:7): [True: 325, False: 20]
  |  Branch (199:34): [True: 320, False: 5]
  ------------------
  200|     25|			gd_error_ex(GD_WARNING, "gd-tga: unsupported truecolor depth %u\n",
  ------------------
  |  |   38|     25|#define GD_WARNING LOG_WARNING
  ------------------
  201|     25|						tga->bits);
  202|     25|			return -1;
  203|     25|		}
  204|    640|		break;
  205|       |
  206|    640|	case TGA_TYPE_GREYSCALE:
  ------------------
  |  |   38|     27|#define TGA_TYPE_GREYSCALE 3
  ------------------
  |  Branch (206:2): [True: 27, False: 826]
  ------------------
  207|     76|	case TGA_TYPE_GREYSCALE_RLE:
  ------------------
  |  |   41|     76|#define TGA_TYPE_GREYSCALE_RLE 11
  ------------------
  |  Branch (207:2): [True: 49, False: 804]
  ------------------
  208|     76|		if (tga->bits != TGA_BPP_8) {
  ------------------
  |  |   45|     76|#define TGA_BPP_8 8
  ------------------
  |  Branch (208:7): [True: 9, False: 67]
  ------------------
  209|      9|			gd_error_ex(GD_WARNING, "gd-tga: unsupported grayscale depth %u\n",
  ------------------
  |  |   38|      9|#define GD_WARNING LOG_WARNING
  ------------------
  210|      9|						tga->bits);
  211|      9|			return -1;
  212|      9|		}
  213|     67|		break;
  214|       |
  215|     67|	default:
  ------------------
  |  Branch (215:2): [True: 1, False: 852]
  ------------------
  216|      1|		gd_error_ex(GD_WARNING, "gd-tga: unsupported image type %u\n",
  ------------------
  |  |   38|      1|#define GD_WARNING LOG_WARNING
  ------------------
  217|      1|					tga->imagetype);
  218|      1|		return -1;
  219|    853|	}
  220|       |
  221|    786|	tga->ident = NULL;
  222|       |
  223|    786|	if (tga->identsize > 0) {
  ------------------
  |  Branch (223:6): [True: 72, False: 714]
  ------------------
  224|     72|		tga->ident = (char *)gdMalloc(tga->identsize * sizeof(char));
  225|     72|		if (tga->ident == NULL) {
  ------------------
  |  Branch (225:7): [True: 0, False: 72]
  ------------------
  226|      0|			return -1;
  227|      0|		}
  228|       |
  229|     72|		if (gdGetBuf(tga->ident, tga->identsize, ctx) != tga->identsize) {
  ------------------
  |  Branch (229:7): [True: 19, False: 53]
  ------------------
  230|     19|			gd_error("fail to read header ident");
  231|     19|			return -1;
  232|     19|		}
  233|     72|	}
  234|       |
  235|    767|	return 1;
  236|    786|}
read_image_tga:
  243|    767|int read_image_tga(gdIOCtx *ctx, oTga *tga) {
  244|    767|	int pixel_count;
  245|    767|	int bitmap_caret = 0;
  246|       |
  247|    767|	if (overflow2(tga->width, tga->height)) {
  ------------------
  |  Branch (247:6): [True: 22, False: 745]
  ------------------
  248|     22|		return -1;
  249|     22|	}
  250|       |
  251|    745|	pixel_count = tga->width * tga->height;
  252|    745|	if (overflow2(pixel_count, sizeof(int))) {
  ------------------
  |  Branch (252:6): [True: 3, False: 742]
  ------------------
  253|      3|		return -1;
  254|      3|	}
  255|       |
  256|    742|	if (tga_read_color_map(ctx, tga) < 0) {
  ------------------
  |  Branch (256:6): [True: 37, False: 705]
  ------------------
  257|     37|		return -1;
  258|     37|	}
  259|       |
  260|       |	/*!	\brief Allocate memory for image block
  261|       |	 *  Allocate a chunk of memory for the image block to be passed into.
  262|       |	 */
  263|    705|	tga->bitmap = (int *)gdMalloc(pixel_count * sizeof(int));
  264|    705|	if (tga->bitmap == NULL)
  ------------------
  |  Branch (264:6): [True: 0, False: 705]
  ------------------
  265|      0|		return -1;
  266|       |
  267|    705|	if (tga_is_rle(tga->imagetype)) {
  ------------------
  |  Branch (267:6): [True: 555, False: 150]
  ------------------
  268|  13.3k|		while (bitmap_caret < pixel_count) {
  ------------------
  |  Branch (268:10): [True: 12.9k, False: 409]
  ------------------
  269|  12.9k|			int packet = gdGetC(ctx);
  270|  12.9k|			int encoded_pixels;
  271|  12.9k|			int pixel;
  272|  12.9k|			int i;
  273|       |
  274|  12.9k|			if (packet == EOF) {
  ------------------
  |  Branch (274:8): [True: 41, False: 12.8k]
  ------------------
  275|     41|				gd_error("gd-tga: premature end of image data\n");
  276|     41|				return -1;
  277|     41|			}
  278|       |
  279|  12.8k|			encoded_pixels = (packet & ~TGA_RLE_FLAG) + 1;
  ------------------
  |  |   50|  12.8k|#define TGA_RLE_FLAG 128
  ------------------
  280|  12.8k|			if (encoded_pixels > pixel_count - bitmap_caret) {
  ------------------
  |  Branch (280:8): [True: 12, False: 12.8k]
  ------------------
  281|     12|				return -1;
  282|     12|			}
  283|       |
  284|  12.8k|			if ((packet & TGA_RLE_FLAG) == TGA_RLE_FLAG) {
  ------------------
  |  |   50|  12.8k|#define TGA_RLE_FLAG 128
  ------------------
              			if ((packet & TGA_RLE_FLAG) == TGA_RLE_FLAG) {
  ------------------
  |  |   50|  12.8k|#define TGA_RLE_FLAG 128
  ------------------
  |  Branch (284:8): [True: 2.54k, False: 10.3k]
  ------------------
  285|  2.54k|				if (tga_read_pixel(ctx, tga, &pixel) < 0) {
  ------------------
  |  Branch (285:9): [True: 29, False: 2.51k]
  ------------------
  286|     29|					return -1;
  287|     29|				}
  288|   253k|				for (i = 0; i < encoded_pixels; i++) {
  ------------------
  |  Branch (288:17): [True: 251k, False: 2.51k]
  ------------------
  289|   251k|					tga->bitmap[bitmap_caret++] = pixel;
  290|   251k|				}
  291|  10.3k|			} else {
  292|  71.2k|				for (i = 0; i < encoded_pixels; i++) {
  ------------------
  |  Branch (292:17): [True: 60.9k, False: 10.2k]
  ------------------
  293|  60.9k|					if (tga_read_pixel(ctx, tga, &pixel) < 0) {
  ------------------
  |  Branch (293:10): [True: 64, False: 60.8k]
  ------------------
  294|     64|						return -1;
  295|     64|					}
  296|  60.8k|					tga->bitmap[bitmap_caret++] = pixel;
  297|  60.8k|				}
  298|  10.3k|			}
  299|  12.8k|		}
  300|    555|	} else {
  301|   202k|		while (bitmap_caret < pixel_count) {
  ------------------
  |  Branch (301:10): [True: 202k, False: 67]
  ------------------
  302|   202k|			if (tga_read_pixel(ctx, tga, &tga->bitmap[bitmap_caret]) < 0) {
  ------------------
  |  Branch (302:8): [True: 83, False: 202k]
  ------------------
  303|     83|				return -1;
  304|     83|			}
  305|   202k|			bitmap_caret++;
  306|   202k|		}
  307|    150|	}
  308|       |
  309|    476|	tga_apply_attribute_type(ctx, tga, pixel_count);
  310|       |
  311|    476|	return 1;
  312|    705|}
free_tga:
  545|    890|void free_tga(oTga *tga) {
  546|    890|	if (tga) {
  ------------------
  |  Branch (546:6): [True: 890, False: 0]
  ------------------
  547|    890|		if (tga->ident)
  ------------------
  |  Branch (547:7): [True: 72, False: 818]
  ------------------
  548|     72|			gdFree(tga->ident);
  549|    890|		if (tga->bitmap)
  ------------------
  |  Branch (549:7): [True: 705, False: 185]
  ------------------
  550|    705|			gdFree(tga->bitmap);
  551|    890|		if (tga->colormap)
  ------------------
  |  Branch (551:7): [True: 164, False: 726]
  ------------------
  552|    164|			gdFree(tga->colormap);
  553|    890|		gdFree(tga);
  554|    890|	}
  555|    890|}
gd_tga.c:tga_is_rle:
  314|    705|static int tga_is_rle(uint8_t imagetype) {
  315|    705|	return imagetype == TGA_TYPE_INDEXED_RLE || imagetype == TGA_TYPE_RGB_RLE ||
  ------------------
  |  |   39|  1.41k|#define TGA_TYPE_INDEXED_RLE 9
  ------------------
              	return imagetype == TGA_TYPE_INDEXED_RLE || imagetype == TGA_TYPE_RGB_RLE ||
  ------------------
  |  |   40|  1.37k|#define TGA_TYPE_RGB_RLE 10
  ------------------
  |  Branch (315:9): [True: 33, False: 672]
  |  Branch (315:46): [True: 482, False: 190]
  ------------------
  316|    190|		   imagetype == TGA_TYPE_GREYSCALE_RLE;
  ------------------
  |  |   41|    190|#define TGA_TYPE_GREYSCALE_RLE 11
  ------------------
  |  Branch (316:6): [True: 40, False: 150]
  ------------------
  317|    705|}
gd_tga.c:tga_read_color_map:
  321|    742|static int tga_read_color_map(gdIOCtx *ctx, oTga *tga) {
  322|    742|	int i;
  323|    742|	int has_alpha = 0;
  324|    742|	int entry_size;
  325|       |
  326|    742|	if (tga->colormaptype == 0) {
  ------------------
  |  Branch (326:6): [True: 570, False: 172]
  ------------------
  327|    570|		return 1;
  328|    570|	}
  329|       |
  330|    172|	if (tga->colormaplength <= 0) {
  ------------------
  |  Branch (330:6): [True: 1, False: 171]
  ------------------
  331|      1|		return -1;
  332|      1|	}
  333|       |
  334|    171|	if (overflow2(tga->colormaplength, sizeof(int))) {
  ------------------
  |  Branch (334:6): [True: 7, False: 164]
  ------------------
  335|      7|		return -1;
  336|      7|	}
  337|       |
  338|    164|	entry_size = tga_pixel_size(tga->colormapbits);
  339|    164|	tga->colormap = (int *)gdMalloc(tga->colormaplength * sizeof(int));
  340|    164|	if (tga->colormap == NULL) {
  ------------------
  |  Branch (340:6): [True: 0, False: 164]
  ------------------
  341|      0|		return -1;
  342|      0|	}
  343|       |
  344|   375k|	for (i = 0; i < tga->colormaplength; i++) {
  ------------------
  |  Branch (344:14): [True: 374k, False: 135]
  ------------------
  345|   374k|		unsigned char buf[4] = {0, 0, 0, 0};
  346|       |
  347|   374k|		if (gdGetBuf(buf, entry_size, ctx) != entry_size) {
  ------------------
  |  Branch (347:7): [True: 29, False: 374k]
  ------------------
  348|     29|			gd_error("gd-tga: premature end of color map data\n");
  349|     29|			return -1;
  350|     29|		}
  351|       |
  352|   374k|		tga->colormap[i] =
  353|   374k|			tga_decode_color(buf, tga->colormapbits,
  354|   374k|							 tga->colormapbits == 32 ? 8 : 0, &has_alpha);
  ------------------
  |  Branch (354:9): [True: 5.72k, False: 369k]
  ------------------
  355|   374k|	}
  356|       |
  357|    135|	if (has_alpha) {
  ------------------
  |  Branch (357:6): [True: 12, False: 123]
  ------------------
  358|     12|		tga->has_alpha = 1;
  359|     12|	}
  360|       |
  361|    135|	return 1;
  362|    164|}
gd_tga.c:tga_pixel_size:
  319|   266k|static int tga_pixel_size(uint8_t bits) { return (bits + 7) / 8; }
gd_tga.c:tga_decode_color:
  486|   634k|							int *has_alpha) {
  487|   634k|	switch (bits) {
  ------------------
  |  Branch (487:10): [True: 265k, False: 368k]
  ------------------
  488|    748|	case 15:
  ------------------
  |  Branch (488:2): [True: 748, False: 633k]
  ------------------
  489|   189k|	case 16:
  ------------------
  |  Branch (489:2): [True: 189k, False: 445k]
  ------------------
  490|   189k|		return tga_decode_16((unsigned int)buf[0] | ((unsigned int)buf[1] << 8),
  491|   189k|							 alpha_bits, has_alpha);
  492|       |
  493|  63.3k|	case 24:
  ------------------
  |  Branch (493:2): [True: 63.3k, False: 571k]
  ------------------
  494|  63.3k|		return gdTrueColor(buf[2], buf[1], buf[0]);
  ------------------
  |  | 1347|  63.3k|#define gdTrueColor(r, g, b) (((r) << 16) + ((g) << 8) + (b))
  ------------------
  495|       |
  496|  12.8k|	case 32:
  ------------------
  |  Branch (496:2): [True: 12.8k, False: 621k]
  ------------------
  497|  12.8k|		if (has_alpha) {
  ------------------
  |  Branch (497:7): [True: 12.8k, False: 0]
  ------------------
  498|  12.8k|			*has_alpha = 1;
  499|  12.8k|		}
  500|  12.8k|		return gdTrueColorAlpha(buf[2], buf[1], buf[0],
  ------------------
  |  | 1371|  12.8k|	(((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
  ------------------
  501|   634k|								tga_alpha_8_to_gd(buf[3]));
  502|   634k|	}
  503|       |
  504|   368k|	return 0;
  505|   634k|}
gd_tga.c:tga_decode_16:
  507|   189k|static int tga_decode_16(unsigned int value, int alpha_bits, int *has_alpha) {
  508|   189k|	int b = tga_scale_5_to_8(value & 0x1f);
  509|   189k|	int g = tga_scale_5_to_8((value >> 5) & 0x1f);
  510|   189k|	int r = tga_scale_5_to_8((value >> 10) & 0x1f);
  511|       |
  512|   189k|	if (alpha_bits > 0) {
  ------------------
  |  Branch (512:6): [True: 188k, False: 995]
  ------------------
  513|   188k|		int a = (value & 0x8000) ? gdAlphaOpaque : gdAlphaTransparent;
  ------------------
  |  |  141|  75.6k|#define gdAlphaOpaque 0
  ------------------
              		int a = (value & 0x8000) ? gdAlphaOpaque : gdAlphaTransparent;
  ------------------
  |  |  142|   113k|#define gdAlphaTransparent 127
  ------------------
  |  Branch (513:11): [True: 75.6k, False: 113k]
  ------------------
  514|       |
  515|   188k|		if (has_alpha) {
  ------------------
  |  Branch (515:7): [True: 188k, False: 0]
  ------------------
  516|   188k|			*has_alpha = 1;
  517|   188k|		}
  518|   188k|		return gdTrueColorAlpha(r, g, b, a);
  ------------------
  |  | 1371|   188k|	(((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
  ------------------
  519|   188k|	}
  520|       |
  521|    995|	return gdTrueColor(r, g, b);
  ------------------
  |  | 1347|    995|#define gdTrueColor(r, g, b) (((r) << 16) + ((g) << 8) + (b))
  ------------------
  522|   189k|}
gd_tga.c:tga_scale_5_to_8:
  524|   569k|static int tga_scale_5_to_8(int c) { return (c * 255) / 31; }
gd_tga.c:tga_alpha_8_to_gd:
  526|  12.8k|static int tga_alpha_8_to_gd(int a) { return gdAlphaMax - (a >> 1); }
  ------------------
  |  |  140|  12.8k|#define gdAlphaMax 127
  ------------------
gd_tga.c:tga_read_pixel:
  364|   266k|static int tga_read_pixel(gdIOCtx *ctx, oTga *tga, int *pixel) {
  365|   266k|	unsigned char buf[4] = {0, 0, 0, 0};
  366|   266k|	int size = tga_pixel_size(tga->bits);
  367|   266k|	int has_alpha = 0;
  368|       |
  369|   266k|	if (gdGetBuf(buf, size, ctx) != size) {
  ------------------
  |  Branch (369:6): [True: 129, False: 266k]
  ------------------
  370|    129|		gd_error("gd-tga: premature end of image data\n");
  371|    129|		return -1;
  372|    129|	}
  373|       |
  374|   266k|	switch (tga->imagetype) {
  375|    219|	case TGA_TYPE_INDEXED:
  ------------------
  |  |   36|    219|#define TGA_TYPE_INDEXED 1
  ------------------
  |  Branch (375:2): [True: 219, False: 265k]
  ------------------
  376|    471|	case TGA_TYPE_INDEXED_RLE: {
  ------------------
  |  |   39|    471|#define TGA_TYPE_INDEXED_RLE 9
  ------------------
  |  Branch (376:2): [True: 252, False: 265k]
  ------------------
  377|    471|		int index = buf[0] - tga->colormapstart;
  378|       |
  379|    471|		if (index < 0 || index >= tga->colormaplength ||
  ------------------
  |  Branch (379:7): [True: 30, False: 441]
  |  Branch (379:20): [True: 17, False: 424]
  ------------------
  380|    424|			tga->colormap == NULL) {
  ------------------
  |  Branch (380:4): [True: 0, False: 424]
  ------------------
  381|     47|			return -1;
  382|     47|		}
  383|    424|		*pixel = tga->colormap[index];
  384|    424|		break;
  385|    471|	}
  386|       |
  387|   201k|	case TGA_TYPE_RGB:
  ------------------
  |  |   37|   201k|#define TGA_TYPE_RGB 2
  ------------------
  |  Branch (387:2): [True: 201k, False: 64.2k]
  ------------------
  388|   259k|	case TGA_TYPE_RGB_RLE:
  ------------------
  |  |   40|   259k|#define TGA_TYPE_RGB_RLE 10
  ------------------
  |  Branch (388:2): [True: 57.7k, False: 208k]
  ------------------
  389|   259k|		*pixel = tga_decode_color(buf, tga->bits, tga->alphabits, &has_alpha);
  390|   259k|		if (has_alpha) {
  ------------------
  |  Branch (390:7): [True: 195k, False: 63.5k]
  ------------------
  391|   195k|			tga->has_alpha = 1;
  392|   195k|		}
  393|   259k|		break;
  394|       |
  395|    615|	case TGA_TYPE_GREYSCALE:
  ------------------
  |  |   38|    615|#define TGA_TYPE_GREYSCALE 3
  ------------------
  |  Branch (395:2): [True: 615, False: 265k]
  ------------------
  396|  6.06k|	case TGA_TYPE_GREYSCALE_RLE:
  ------------------
  |  |   41|  6.06k|#define TGA_TYPE_GREYSCALE_RLE 11
  ------------------
  |  Branch (396:2): [True: 5.44k, False: 260k]
  ------------------
  397|  6.06k|		*pixel = gdTrueColor(buf[0], buf[0], buf[0]);
  ------------------
  |  | 1347|  6.06k|#define gdTrueColor(r, g, b) (((r) << 16) + ((g) << 8) + (b))
  ------------------
  398|  6.06k|		break;
  399|       |
  400|      0|	default:
  ------------------
  |  Branch (400:2): [True: 0, False: 266k]
  ------------------
  401|      0|		return -1;
  402|   266k|	}
  403|       |
  404|   265k|	return 1;
  405|   266k|}
gd_tga.c:tga_apply_attribute_type:
  407|    476|static void tga_apply_attribute_type(gdIOCtx *ctx, oTga *tga, int pixel_count) {
  408|    476|	static const unsigned char signature[18] = {'T', 'R', 'U', 'E', 'V', 'I',
  409|    476|												'S', 'I', 'O', 'N', '-', 'X',
  410|    476|												'F', 'I', 'L', 'E', '.', '\0'};
  411|    476|	unsigned char footer[26];
  412|    476|	unsigned char *rest = NULL;
  413|    476|	int rest_size = 0;
  414|    476|	int rest_alloc = 0;
  415|    476|	int c;
  416|    476|	long start;
  417|    476|	int extension_offset;
  418|    476|	int attr_type_offset;
  419|    476|	int attr_type;
  420|       |
  421|    476|	if (!tga->has_alpha) {
  ------------------
  |  Branch (421:6): [True: 99, False: 377]
  ------------------
  422|     99|		return;
  423|     99|	}
  424|       |
  425|    377|	start = gdTell(ctx);
  426|    377|	if (start < 0) {
  ------------------
  |  Branch (426:6): [True: 0, False: 377]
  ------------------
  427|      0|		return;
  428|      0|	}
  429|       |
  430|  1.14M|	while ((c = gdGetC(ctx)) != EOF) {
  ------------------
  |  Branch (430:9): [True: 1.14M, False: 367]
  ------------------
  431|  1.14M|		if (rest_size == rest_alloc) {
  ------------------
  |  Branch (431:7): [True: 525, False: 1.14M]
  ------------------
  432|    525|			int new_alloc = rest_alloc == 0 ? 1024 : rest_alloc * 2;
  ------------------
  |  Branch (432:20): [True: 359, False: 166]
  ------------------
  433|    525|			unsigned char *tmp;
  434|       |
  435|    525|			if (new_alloc < rest_alloc ||
  ------------------
  |  Branch (435:8): [True: 0, False: 525]
  ------------------
  436|    525|				overflow2(new_alloc, sizeof(unsigned char))) {
  ------------------
  |  Branch (436:5): [True: 10, False: 515]
  ------------------
  437|     10|				gdFree(rest);
  438|     10|				return;
  439|     10|			}
  440|       |
  441|    515|			tmp = (unsigned char *)gdRealloc(rest,
  442|    515|											 new_alloc * sizeof(unsigned char));
  443|    515|			if (tmp == NULL) {
  ------------------
  |  Branch (443:8): [True: 0, False: 515]
  ------------------
  444|      0|				gdFree(rest);
  445|      0|				return;
  446|      0|			}
  447|    515|			rest = tmp;
  448|    515|			rest_alloc = new_alloc;
  449|    515|		}
  450|  1.14M|		rest[rest_size++] = (unsigned char)c;
  451|  1.14M|	}
  452|       |
  453|    367|	if (rest_size < 26) {
  ------------------
  |  Branch (453:6): [True: 54, False: 313]
  ------------------
  454|     54|		gdFree(rest);
  455|     54|		return;
  456|     54|	}
  457|       |
  458|    313|	memcpy(footer, rest + rest_size - 26, sizeof(footer));
  459|    313|	if (memcmp(footer + 8, signature, sizeof(signature)) != 0) {
  ------------------
  |  Branch (459:6): [True: 165, False: 148]
  ------------------
  460|    165|		gdFree(rest);
  461|    165|		return;
  462|    165|	}
  463|       |
  464|    148|	extension_offset =
  465|    148|		footer[0] | (footer[1] << 8) | (footer[2] << 16) | (footer[3] << 24);
  466|    148|	if (extension_offset <= 0 || extension_offset < start) {
  ------------------
  |  Branch (466:6): [True: 37, False: 111]
  |  Branch (466:31): [True: 11, False: 100]
  ------------------
  467|     48|		gdFree(rest);
  468|     48|		return;
  469|     48|	}
  470|       |
  471|    100|	attr_type_offset = extension_offset - (int)start + 494;
  472|    100|	if (attr_type_offset < 0 || attr_type_offset >= rest_size) {
  ------------------
  |  Branch (472:6): [True: 0, False: 100]
  |  Branch (472:30): [True: 77, False: 23]
  ------------------
  473|     77|		gdFree(rest);
  474|     77|		return;
  475|     77|	}
  476|       |
  477|     23|	attr_type = rest[attr_type_offset];
  478|     23|	if (attr_type != 3 && attr_type != 4) {
  ------------------
  |  Branch (478:6): [True: 22, False: 1]
  |  Branch (478:24): [True: 21, False: 1]
  ------------------
  479|     21|		tga_strip_alpha(tga, pixel_count);
  480|     21|	}
  481|       |
  482|     23|	gdFree(rest);
  483|     23|}
gd_tga.c:tga_strip_alpha:
  528|     21|static void tga_strip_alpha(oTga *tga, int pixel_count) {
  529|     21|	int i;
  530|       |
  531|  2.67k|	for (i = 0; i < pixel_count; i++) {
  ------------------
  |  Branch (531:14): [True: 2.65k, False: 21]
  ------------------
  532|  2.65k|		int pixel = tga->bitmap[i];
  533|       |
  534|  2.65k|		tga->bitmap[i] =
  535|  2.65k|			gdTrueColor(gdTrueColorGetRed(pixel), gdTrueColorGetGreen(pixel),
  ------------------
  |  | 1347|  2.65k|#define gdTrueColor(r, g, b) (((r) << 16) + ((g) << 8) + (b))
  ------------------
  536|  2.65k|						gdTrueColorGetBlue(pixel));
  537|  2.65k|	}
  538|     21|	tga->has_alpha = 0;
  539|     21|}

gdImageFlipVertical:
   25|    139|BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im) {
   26|    139|	register int x, y;
   27|       |
   28|    139|	if (im->trueColor) {
  ------------------
  |  Branch (28:6): [True: 139, False: 0]
  ------------------
   29|  17.7k|		for (y = 0; y < im->sy / 2; y++) {
  ------------------
  |  Branch (29:15): [True: 17.6k, False: 139]
  ------------------
   30|  17.6k|			int *row_dst = im->tpixels[y];
   31|  17.6k|			int *row_src = im->tpixels[im->sy - 1 - y];
   32|  44.6k|			for (x = 0; x < im->sx; x++) {
  ------------------
  |  Branch (32:16): [True: 27.0k, False: 17.6k]
  ------------------
   33|  27.0k|				register int p;
   34|  27.0k|				p = row_dst[x];
   35|  27.0k|				row_dst[x] = im->tpixels[im->sy - 1 - y][x];
   36|  27.0k|				row_src[x] = p;
   37|  27.0k|			}
   38|  17.6k|		}
   39|    139|	} else {
   40|      0|		unsigned char p;
   41|      0|		for (y = 0; y < im->sy / 2; y++) {
  ------------------
  |  Branch (41:15): [True: 0, False: 0]
  ------------------
   42|      0|			for (x = 0; x < im->sx; x++) {
  ------------------
  |  Branch (42:16): [True: 0, False: 0]
  ------------------
   43|      0|				p = im->pixels[y][x];
   44|      0|				im->pixels[y][x] = im->pixels[im->sy - 1 - y][x];
   45|      0|				im->pixels[im->sy - 1 - y][x] = p;
   46|      0|			}
   47|      0|		}
   48|      0|	}
   49|    139|	return;
   50|    139|}
gdImageFlipHorizontal:
   66|    433|BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im) {
   67|       |
   68|    433|	int x, y;
   69|       |
   70|    433|	if (im->trueColor) {
  ------------------
  |  Branch (70:6): [True: 433, False: 0]
  ------------------
   71|    433|		int *px1, *px2, tmp;
   72|       |
   73|  49.7k|		for (y = 0; y < im->sy; y++) {
  ------------------
  |  Branch (73:15): [True: 49.2k, False: 433]
  ------------------
   74|  49.2k|			px1 = im->tpixels[y];
   75|  49.2k|			px2 = im->tpixels[y] + im->sx - 1;
   76|   105k|			for (x = 0; x < (im->sx >> 1); x++) {
  ------------------
  |  Branch (76:16): [True: 56.5k, False: 49.2k]
  ------------------
   77|  56.5k|				tmp = *px1;
   78|  56.5k|				*px1 = *px2;
   79|  56.5k|				*px2 = tmp;
   80|  56.5k|				px1++;
   81|  56.5k|				px2--;
   82|  56.5k|			}
   83|  49.2k|		}
   84|    433|	} else {
   85|      0|		unsigned char *px1, *px2, tmp;
   86|       |
   87|      0|		for (y = 0; y < im->sy; y++) {
  ------------------
  |  Branch (87:15): [True: 0, False: 0]
  ------------------
   88|      0|			px1 = im->pixels[y];
   89|      0|			px2 = im->pixels[y] + im->sx - 1;
   90|      0|			for (x = 0; x < (im->sx >> 1); x++) {
  ------------------
  |  Branch (90:16): [True: 0, False: 0]
  ------------------
   91|      0|				tmp = *px1;
   92|      0|				*px1 = *px2;
   93|      0|				*px2 = tmp;
   94|      0|				px1++;
   95|      0|				px2--;
   96|      0|			}
   97|      0|		}
   98|      0|	}
   99|    433|}
gdImageFlipBoth:
  115|    113|BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im) {
  116|    113|	gdImageFlipVertical(im);
  117|    113|	gdImageFlipHorizontal(im);
  118|    113|}

gdCalloc:
   65|  54.6k|void *gdCalloc(size_t nmemb, size_t size) { return calloc(nmemb, size); }
gdMalloc:
   67|  4.54k|void *gdMalloc(size_t size) { return malloc(size); }
gdRealloc:
   69|    515|void *gdRealloc(void *ptr, size_t size) { return realloc(ptr, size); }
gdFree:
   98|  59.5k|BGD_DECLARE(void) gdFree(void *ptr) { free(ptr); }

LLVMFuzzerTestOneInput:
   23|    890|extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   24|    890|    gdImagePtr im = CREATE_IMAGE(FUZZ_GD_FORMAT)(Size, (void*) Data);
  ------------------
  |  |   21|    890|#define CREATE_IMAGE(FORMAT) PASTE(FORMAT)
  |  |  ------------------
  |  |  |  |   20|    890|#define PASTE(x) gdImageCreateFrom ## x ## Ptr
  |  |  ------------------
  ------------------
   25|    890|    if (im) gdImageDestroy(im);
  ------------------
  |  Branch (25:9): [True: 466, False: 424]
  ------------------
   26|    890|    return 0;
   27|    890|}

