gd_error_ex:
  103|     94|{
  104|     94|    va_list args;
  105|       |
  106|     94|    va_start(args, format);
  107|     94|    _gd_error_ex(priority, format, args);
  108|       |    va_end(args);
  109|     94|}
gdImageCreate:
  162|     72|{
  163|     72|    int i;
  164|     72|    gdImagePtr im;
  165|       |
  166|     72|    if (overflow2(sx, sy)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 72]
  ------------------
  167|      0|        return NULL;
  168|      0|    }
  169|       |
  170|     72|    if (overflow2(sizeof(unsigned char *), sy)) {
  ------------------
  |  Branch (170:9): [True: 7, False: 65]
  ------------------
  171|      7|        return NULL;
  172|      7|    }
  173|     65|    if (overflow2(sizeof(unsigned char), sx)) {
  ------------------
  |  Branch (173:9): [True: 0, False: 65]
  ------------------
  174|      0|        return NULL;
  175|      0|    }
  176|       |
  177|     65|    im = (gdImage *)gdCalloc(1, sizeof(gdImage));
  178|     65|    if (!im) {
  ------------------
  |  Branch (178:9): [True: 0, False: 65]
  ------------------
  179|      0|        return NULL;
  180|      0|    }
  181|       |
  182|       |    /* Row-major ever since gd 1.3 */
  183|     65|    im->pixels = (unsigned char **)gdMalloc(sizeof(unsigned char *) * sy);
  184|     65|    if (!im->pixels) {
  ------------------
  |  Branch (184:9): [True: 0, False: 65]
  ------------------
  185|      0|        gdFree(im);
  186|      0|        return NULL;
  187|      0|    }
  188|       |
  189|     65|    im->polyInts = 0;
  190|     65|    im->polyAllocated = 0;
  191|     65|    im->brush = 0;
  192|     65|    im->tile = 0;
  193|     65|    im->style = 0;
  194|  84.2k|    for (i = 0; (i < sy); i++) {
  ------------------
  |  Branch (194:17): [True: 84.1k, False: 65]
  ------------------
  195|       |        /* Row-major ever since gd 1.3 */
  196|  84.1k|        im->pixels[i] = (unsigned char *)gdCalloc(sx, sizeof(unsigned char));
  197|  84.1k|        if (!im->pixels[i]) {
  ------------------
  |  Branch (197:13): [True: 0, False: 84.1k]
  ------------------
  198|      0|            for (--i; i >= 0; i--) {
  ------------------
  |  Branch (198:23): [True: 0, False: 0]
  ------------------
  199|      0|                gdFree(im->pixels[i]);
  200|      0|            }
  201|      0|            gdFree(im->pixels);
  202|      0|            gdFree(im);
  203|      0|            return NULL;
  204|      0|        }
  205|  84.1k|    }
  206|     65|    im->sx = sx;
  207|     65|    im->sy = sy;
  208|     65|    im->colorsTotal = 0;
  209|     65|    im->transparent = (-1);
  210|     65|    im->interlace = 0;
  211|     65|    im->thick = 1;
  212|     65|    im->AA = 0;
  213|  16.7k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  16.7k|#define gdMaxColors 256
  ------------------
  |  Branch (213:17): [True: 16.6k, False: 65]
  ------------------
  214|  16.6k|        im->open[i] = 1;
  215|  16.6k|        im->red[i] = 0;
  216|  16.6k|        im->green[i] = 0;
  217|  16.6k|        im->blue[i] = 0;
  218|  16.6k|    };
  219|     65|    im->trueColor = 0;
  220|     65|    im->tpixels = 0;
  221|     65|    im->cx1 = 0;
  222|     65|    im->cy1 = 0;
  223|     65|    im->cx2 = im->sx - 1;
  224|     65|    im->cy2 = im->sy - 1;
  225|     65|    im->res_x = GD_RESOLUTION;
  ------------------
  |  | 8517|     65|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  226|     65|    im->res_y = GD_RESOLUTION;
  ------------------
  |  | 8517|     65|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  227|       |    im->interpolation = NULL;
  228|     65|    im->interpolation_id = GD_BILINEAR_FIXED;
  229|     65|    return im;
  230|     65|}
gdImageDestroy:
  340|     65|{
  341|     65|    int i;
  342|     65|    if (im->pixels) {
  ------------------
  |  Branch (342:9): [True: 65, False: 0]
  ------------------
  343|  84.2k|        for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (343:21): [True: 84.1k, False: 65]
  ------------------
  344|  84.1k|            gdFree(im->pixels[i]);
  345|  84.1k|        }
  346|     65|        gdFree(im->pixels);
  347|     65|    }
  348|     65|    if (im->tpixels) {
  ------------------
  |  Branch (348:9): [True: 0, False: 65]
  ------------------
  349|      0|        for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (349:21): [True: 0, False: 0]
  ------------------
  350|      0|            gdFree(im->tpixels[i]);
  351|      0|        }
  352|      0|        gdFree(im->tpixels);
  353|      0|    }
  354|     65|    if (im->polyInts) {
  ------------------
  |  Branch (354:9): [True: 0, False: 65]
  ------------------
  355|      0|        gdFree(im->polyInts);
  356|      0|    }
  357|     65|    if (im->style) {
  ------------------
  |  Branch (357:9): [True: 0, False: 65]
  ------------------
  358|      0|        gdFree(im->style);
  359|      0|    }
  360|     65|    gdFree(im);
  361|     65|}
gdImageColorAllocate:
  544|    130|{
  545|    130|    return gdImageColorAllocateAlpha(im, r, g, b, gdAlphaOpaque);
  ------------------
  |  |  141|    130|#define gdAlphaOpaque 0
  ------------------
  546|    130|}
gdImageColorAllocateAlpha:
  550|    130|{
  551|    130|    int i;
  552|    130|    int ct = (-1);
  553|    130|    if (im->trueColor) {
  ------------------
  |  Branch (553:9): [True: 0, False: 130]
  ------------------
  554|      0|        return gdTrueColorAlpha(r, g, b, a);
  ------------------
  |  | 6061|      0|#define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
  ------------------
  555|      0|    }
  556|    195|    for (i = 0; (i < (im->colorsTotal)); i++) {
  ------------------
  |  Branch (556:17): [True: 65, False: 130]
  ------------------
  557|     65|        if (im->open[i]) {
  ------------------
  |  Branch (557:13): [True: 0, False: 65]
  ------------------
  558|      0|            ct = i;
  559|      0|            break;
  560|      0|        }
  561|     65|    }
  562|    130|    if (ct == (-1)) {
  ------------------
  |  Branch (562:9): [True: 130, False: 0]
  ------------------
  563|    130|        ct = im->colorsTotal;
  564|    130|        if (ct == gdMaxColors) {
  ------------------
  |  |  117|    130|#define gdMaxColors 256
  ------------------
  |  Branch (564:13): [True: 0, False: 130]
  ------------------
  565|      0|            return -1;
  566|      0|        }
  567|    130|        im->colorsTotal++;
  568|    130|    }
  569|    130|    im->red[ct] = r;
  570|    130|    im->green[ct] = g;
  571|    130|    im->blue[ct] = b;
  572|    130|    im->alpha[ct] = a;
  573|    130|    im->open[ct] = 0;
  574|       |
  575|    130|    return ct;
  576|    130|}
gdImageSetPixel:
  966|   273k|{
  967|   273k|    int p;
  968|   273k|    switch (color) {
  969|      0|    case gdStyled:
  ------------------
  |  |  616|      0|#define gdStyled (-2)
  ------------------
  |  Branch (969:5): [True: 0, False: 273k]
  ------------------
  970|      0|        if (!im->style) {
  ------------------
  |  Branch (970:13): [True: 0, False: 0]
  ------------------
  971|       |            /* Refuse to draw if no style is set. */
  972|      0|            return;
  973|      0|        } else {
  974|      0|            p = im->style[im->stylePos++];
  975|      0|        }
  976|      0|        if (p != (gdTransparent)) {
  ------------------
  |  |  623|      0|#define gdTransparent (-6)
  ------------------
  |  Branch (976:13): [True: 0, False: 0]
  ------------------
  977|      0|            gdImageSetPixel(im, x, y, p);
  978|      0|        }
  979|      0|        im->stylePos = im->stylePos % im->styleLength;
  980|      0|        break;
  981|      0|    case gdStyledBrushed:
  ------------------
  |  |  618|      0|#define gdStyledBrushed (-4)
  ------------------
  |  Branch (981:5): [True: 0, False: 273k]
  ------------------
  982|      0|        if (!im->style) {
  ------------------
  |  Branch (982:13): [True: 0, False: 0]
  ------------------
  983|       |            /* Refuse to draw if no style is set. */
  984|      0|            return;
  985|      0|        }
  986|      0|        p = im->style[im->stylePos++];
  987|      0|        if ((p != gdTransparent) && (p != 0)) {
  ------------------
  |  |  623|      0|#define gdTransparent (-6)
  ------------------
  |  Branch (987:13): [True: 0, False: 0]
  |  Branch (987:37): [True: 0, False: 0]
  ------------------
  988|      0|            gdImageSetPixel(im, x, y, gdBrushed);
  ------------------
  |  |  617|      0|#define gdBrushed (-3)
  ------------------
  989|      0|        }
  990|      0|        im->stylePos = im->stylePos % im->styleLength;
  991|      0|        break;
  992|      0|    case gdBrushed:
  ------------------
  |  |  617|      0|#define gdBrushed (-3)
  ------------------
  |  Branch (992:5): [True: 0, False: 273k]
  ------------------
  993|      0|        gdImageBrushApply(im, x, y);
  994|      0|        break;
  995|      0|    case gdTiled:
  ------------------
  |  |  619|      0|#define gdTiled (-5)
  ------------------
  |  Branch (995:5): [True: 0, False: 273k]
  ------------------
  996|      0|        gdImageTileApply(im, x, y);
  997|      0|        break;
  998|      0|    case gdAntiAliased:
  ------------------
  |  |  625|      0|#define gdAntiAliased (-7)
  ------------------
  |  Branch (998:5): [True: 0, False: 273k]
  ------------------
  999|       |        /* This shouldn't happen (2.0.26) because we just call
 1000|       |          gdImageAALine now, but do something sane. */
 1001|      0|        gdImageSetPixel(im, x, y, im->AA_color);
 1002|      0|        break;
 1003|   273k|    default:
  ------------------
  |  Branch (1003:5): [True: 273k, False: 0]
  ------------------
 1004|   273k|        if (gdImageBoundsSafeMacro(im, x, y)) {
  ------------------
  |  |   60|   273k|    (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
  |  |  ------------------
  |  |  |  Branch (60:9): [True: 0, False: 273k]
  |  |  |  Branch (60:30): [True: 0, False: 273k]
  |  |  |  Branch (60:53): [True: 0, False: 273k]
  |  |  |  Branch (60:74): [True: 0, False: 273k]
  |  |  ------------------
  ------------------
 1005|   273k|            if (im->trueColor) {
  ------------------
  |  Branch (1005:17): [True: 0, False: 273k]
  ------------------
 1006|      0|                switch (im->alphaBlendingFlag) {
 1007|      0|                default:
  ------------------
  |  Branch (1007:17): [True: 0, False: 0]
  ------------------
 1008|      0|                case gdEffectReplace:
  ------------------
  |  |  225|      0|#define gdEffectReplace 0
  ------------------
  |  Branch (1008:17): [True: 0, False: 0]
  ------------------
 1009|      0|                    im->tpixels[y][x] = color;
 1010|      0|                    break;
 1011|      0|                case gdEffectAlphaBlend:
  ------------------
  |  |  226|      0|#define gdEffectAlphaBlend 1
  ------------------
  |  Branch (1011:17): [True: 0, False: 0]
  ------------------
 1012|      0|                case gdEffectNormal:
  ------------------
  |  |  227|      0|#define gdEffectNormal 2
  ------------------
  |  Branch (1012:17): [True: 0, False: 0]
  ------------------
 1013|      0|                    im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
 1014|      0|                    break;
 1015|      0|                case gdEffectOverlay:
  ------------------
  |  |  228|      0|#define gdEffectOverlay 3
  ------------------
  |  Branch (1015:17): [True: 0, False: 0]
  ------------------
 1016|      0|                    im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
 1017|      0|                    break;
 1018|      0|                case gdEffectMultiply:
  ------------------
  |  |  229|      0|#define gdEffectMultiply 4
  ------------------
  |  Branch (1018:17): [True: 0, False: 0]
  ------------------
 1019|      0|                    im->tpixels[y][x] = gdLayerMultiply(im->tpixels[y][x], color);
 1020|      0|                    break;
 1021|      0|                }
 1022|   273k|            } else {
 1023|   273k|                im->pixels[y][x] = color;
 1024|   273k|            }
 1025|   273k|        }
 1026|   273k|        break;
 1027|   273k|    }
 1028|   273k|}
gd.c:_gd_error_ex:
   88|     94|{
   89|     94|    if (gd_error_method) {
  ------------------
  |  Branch (89:9): [True: 94, False: 0]
  ------------------
   90|     94|        gd_error_method(priority, format, args);
   91|     94|    }
   92|     94|}
gd.c:gd_stderr_error:
   63|     94|{
   64|     94|    switch (priority) {
  ------------------
  |  Branch (64:13): [True: 94, False: 0]
  ------------------
   65|      0|    case GD_ERROR:
  ------------------
  |  |   37|      0|#define GD_ERROR LOG_ERR
  ------------------
  |  Branch (65:5): [True: 0, False: 94]
  ------------------
   66|      0|        fputs("GD Error: ", stderr);
   67|      0|        break;
   68|     94|    case GD_WARNING:
  ------------------
  |  |   38|     94|#define GD_WARNING LOG_WARNING
  ------------------
  |  Branch (68:5): [True: 94, False: 0]
  ------------------
   69|     94|        fputs("GD Warning: ", stderr);
   70|     94|        break;
   71|      0|    case GD_NOTICE:
  ------------------
  |  |   39|      0|#define GD_NOTICE LOG_NOTICE
  ------------------
  |  Branch (71:5): [True: 0, False: 94]
  ------------------
   72|      0|        fputs("GD Notice: ", stderr);
   73|      0|        break;
   74|      0|    case GD_INFO:
  ------------------
  |  |   40|      0|#define GD_INFO LOG_INFO
  ------------------
  |  Branch (74:5): [True: 0, False: 94]
  ------------------
   75|      0|        fputs("GD Info: ", stderr);
   76|      0|        break;
   77|      0|    case GD_DEBUG:
  ------------------
  |  |   41|      0|#define GD_DEBUG LOG_DEBUG
  ------------------
  |  Branch (77:5): [True: 0, False: 94]
  ------------------
   78|      0|        fputs("GD Debug: ", stderr);
   79|      0|        break;
   80|     94|    }
   81|     94|    vfprintf(stderr, format, args);
   82|       |    fflush(stderr);
   83|     94|}

gdGetC:
   52|  4.39M|int gdGetC(gdIOCtx *ctx) { return ((ctx->getC)(ctx)); }

gdNewDynamicCtxEx:
   81|    287|{
   82|    287|    dpIOCtx *ctx;
   83|    287|    dynamicPtr *dp;
   84|       |
   85|    287|    ctx = (dpIOCtx *)gdMalloc(sizeof(dpIOCtx));
   86|    287|    if (ctx == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 287]
  ------------------
   87|      0|        return NULL;
   88|      0|    }
   89|       |
   90|    287|    dp = newDynamic(initialSize, data, freeOKFlag);
   91|    287|    if (!dp) {
  ------------------
  |  Branch (91:9): [True: 0, False: 287]
  ------------------
   92|      0|        gdFree(ctx);
   93|      0|        return NULL;
   94|    287|    };
   95|       |
   96|    287|    ctx->dp = dp;
   97|       |
   98|    287|    ctx->ctx.getC = dynamicGetchar;
   99|    287|    ctx->ctx.putC = dynamicPutchar;
  100|       |
  101|    287|    ctx->ctx.getBuf = dynamicGetbuf;
  102|    287|    ctx->ctx.putBuf = dynamicPutbuf;
  103|       |
  104|    287|    ctx->ctx.seek = dynamicSeek;
  105|    287|    ctx->ctx.tell = dynamicTell;
  106|       |
  107|    287|    ctx->ctx.gd_free = gdFreeDynamicCtx;
  108|       |
  109|    287|    return (gdIOCtx *)ctx;
  110|    287|}
gd_io_dp.c:gdFreeDynamicCtx:
  146|    287|{
  147|    287|    dynamicPtr *dp;
  148|    287|    dpIOCtx *dctx;
  149|       |
  150|    287|    dctx = (dpIOCtx *)ctx;
  151|    287|    dp = dctx->dp;
  152|       |
  153|    287|    gdFree(ctx);
  154|       |
  155|       |    /* clean up the data block and return it */
  156|       |    /* 2.0.21: never free memory we don't own */
  157|    287|    if ((dp->data != NULL) && (dp->freeOK)) {
  ------------------
  |  Branch (157:9): [True: 287, False: 0]
  |  Branch (157:31): [True: 0, False: 287]
  ------------------
  158|      0|        gdFree(dp->data);
  159|      0|        dp->data = NULL;
  160|      0|    }
  161|       |
  162|    287|    dp->realSize = 0;
  163|    287|    dp->logicalSize = 0;
  164|       |
  165|    287|    gdFree(dp);
  166|    287|}
gd_io_dp.c:newDynamic:
  224|    287|{
  225|    287|    dynamicPtr *dp;
  226|       |
  227|    287|    dp = (dynamicPtr *)gdMalloc(sizeof(dynamicPtr));
  228|    287|    if (dp == NULL) {
  ------------------
  |  Branch (228:9): [True: 0, False: 287]
  ------------------
  229|      0|        return NULL;
  230|      0|    }
  231|       |
  232|    287|    if (!allocDynamic(dp, initialSize, data)) {
  ------------------
  |  Branch (232:9): [True: 0, False: 287]
  ------------------
  233|      0|        gdFree(dp);
  234|      0|        return NULL;
  235|      0|    }
  236|       |
  237|    287|    dp->pos = 0;
  238|    287|    dp->freeOK = freeOKFlag;
  239|       |
  240|    287|    return dp;
  241|    287|}
gd_io_dp.c:allocDynamic:
  325|    287|{
  326|    287|    if (data == NULL) {
  ------------------
  |  Branch (326:9): [True: 0, False: 287]
  ------------------
  327|      0|        dp->logicalSize = 0;
  328|      0|        dp->dataGood = FALSE;
  ------------------
  |  |   29|      0|#define FALSE 0
  ------------------
  329|      0|        dp->data = gdMalloc(initialSize);
  330|    287|    } else {
  331|    287|        dp->logicalSize = initialSize;
  332|    287|        dp->dataGood = TRUE;
  ------------------
  |  |   28|    287|#define TRUE 1
  ------------------
  333|    287|        dp->data = data;
  334|    287|    }
  335|       |
  336|    287|    if (dp->data != NULL) {
  ------------------
  |  Branch (336:9): [True: 287, False: 0]
  ------------------
  337|    287|        dp->realSize = initialSize;
  338|    287|        dp->dataGood = TRUE;
  ------------------
  |  |   28|    287|#define TRUE 1
  ------------------
  339|    287|        dp->pos = 0;
  340|    287|        return TRUE;
  ------------------
  |  |   28|    287|#define TRUE 1
  ------------------
  341|    287|    } else {
  342|      0|        dp->realSize = 0;
  343|      0|        return FALSE;
  ------------------
  |  |   29|      0|#define FALSE 0
  ------------------
  344|      0|    }
  345|    287|}
gd_io_dp.c:dynamicGetbuf:
  270|  4.39M|{
  271|  4.39M|    int rlen, remain;
  272|  4.39M|    dpIOCtxPtr dctx;
  273|  4.39M|    dynamicPtr *dp;
  274|       |
  275|  4.39M|    dctx = (dpIOCtxPtr)ctx;
  276|  4.39M|    dp = dctx->dp;
  277|       |
  278|  4.39M|    if (dp->pos < 0 || dp->pos >= dp->realSize) {
  ------------------
  |  Branch (278:9): [True: 0, False: 4.39M]
  |  Branch (278:24): [True: 193k, False: 4.19M]
  ------------------
  279|   193k|        return 0;
  280|   193k|    }
  281|       |
  282|  4.19M|    remain = dp->logicalSize - dp->pos;
  283|  4.19M|    if (remain >= len) {
  ------------------
  |  Branch (283:9): [True: 4.19M, False: 0]
  ------------------
  284|  4.19M|        rlen = len;
  285|  4.19M|    } else {
  286|      0|        if (remain <= 0) {
  ------------------
  |  Branch (286:13): [True: 0, False: 0]
  ------------------
  287|      0|            return 0;
  288|      0|        }
  289|       |
  290|      0|        rlen = remain;
  291|      0|    }
  292|       |
  293|  4.19M|    if (dp->pos + rlen > dp->realSize) {
  ------------------
  |  Branch (293:9): [True: 0, False: 4.19M]
  ------------------
  294|      0|        rlen = dp->realSize - dp->pos;
  295|      0|    }
  296|       |
  297|  4.19M|    if (rlen < 0) {
  ------------------
  |  Branch (297:9): [True: 0, False: 4.19M]
  ------------------
  298|      0|        return 0;
  299|      0|    }
  300|       |
  301|  4.19M|    memcpy(buf, (void *)((char *)dp->data + dp->pos), rlen);
  302|  4.19M|    dp->pos += rlen;
  303|       |
  304|  4.19M|    return rlen;
  305|  4.19M|}
gd_io_dp.c:dynamicGetchar:
  308|  4.39M|{
  309|  4.39M|    unsigned char b;
  310|  4.39M|    int rv;
  311|       |
  312|  4.39M|    rv = dynamicGetbuf(ctx, &b, 1);
  313|       |
  314|  4.39M|    if (rv != 1) {
  ------------------
  |  Branch (314:9): [True: 193k, False: 4.19M]
  ------------------
  315|   193k|        return EOF;
  316|  4.19M|    } else {
  317|  4.19M|        return b; /* (b & 0xff); */
  318|  4.19M|    }
  319|  4.39M|}

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

gdImageCreateFromWBMPCtx:
  129|    287|{
  130|    287|    Wbmp *wbmp;
  131|    287|    gdImagePtr im = NULL;
  132|    287|    int black, white;
  133|    287|    int col, row, pos;
  134|       |
  135|    287|    if (readwbmp(&gd_getin, infile, &wbmp)) {
  ------------------
  |  Branch (135:9): [True: 215, False: 72]
  ------------------
  136|    215|        return (NULL);
  137|    215|    }
  138|       |
  139|     72|    if (!(im = gdImageCreate(wbmp->width, wbmp->height))) {
  ------------------
  |  Branch (139:9): [True: 7, False: 65]
  ------------------
  140|      7|        freewbmp(wbmp);
  141|      7|        return NULL;
  142|      7|    }
  143|       |
  144|       |    /* create the background color */
  145|     65|    white = gdImageColorAllocate(im, 255, 255, 255);
  146|       |    /* create foreground color */
  147|     65|    black = gdImageColorAllocate(im, 0, 0, 0);
  148|       |
  149|       |    /* fill in image (in a wbmp 1 = white/ 0 = black) */
  150|     65|    pos = 0;
  151|  84.2k|    for (row = 0; row < wbmp->height; row++) {
  ------------------
  |  Branch (151:19): [True: 84.1k, False: 65]
  ------------------
  152|   357k|        for (col = 0; col < wbmp->width; col++) {
  ------------------
  |  Branch (152:23): [True: 273k, False: 84.1k]
  ------------------
  153|   273k|            if (wbmp->bitmap[pos++] == WBMP_WHITE) {
  ------------------
  |  |   31|   273k|#define WBMP_WHITE 1
  ------------------
  |  Branch (153:17): [True: 268k, False: 5.33k]
  ------------------
  154|   268k|                gdImageSetPixel(im, col, row, white);
  155|   268k|            } else {
  156|  5.33k|                gdImageSetPixel(im, col, row, black);
  157|  5.33k|            }
  158|   273k|        }
  159|  84.1k|    }
  160|       |
  161|     65|    freewbmp(wbmp);
  162|       |
  163|     65|    return im;
  164|     72|}
gdImageCreateFromWBMPPtr:
  178|    287|{
  179|    287|    gdImagePtr im;
  180|    287|    gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
  181|    287|    if (!in) {
  ------------------
  |  Branch (181:9): [True: 0, False: 287]
  ------------------
  182|      0|        return 0;
  183|      0|    }
  184|    287|    im = gdImageCreateFromWBMPCtx(in);
  185|    287|    in->gd_free(in);
  186|    287|    return im;
  187|    287|}
gd_wbmp.c:gd_getin:
   83|  4.39M|static int gd_getin(void *in) { return (gdGetC((gdIOCtx *)in)); }

gdCalloc:
   66|  84.2k|void *gdCalloc(size_t nmemb, size_t size) { return calloc(nmemb, size); }
gdMalloc:
   68|    998|void *gdMalloc(size_t size) { return malloc(size); }
gdFree:
  100|  85.2k|BGD_DECLARE(void) gdFree(void *ptr) { free(ptr); }

getmbi:
   40|    509|{
   41|    509|    unsigned int mbi = 0;
   42|    509|    int i;
   43|       |
   44|  4.13M|    do {
   45|  4.13M|        i = getin(in);
   46|  4.13M|        if (i < 0) {
  ------------------
  |  Branch (46:13): [True: 104, False: 4.13M]
  ------------------
   47|    104|            return (-1);
   48|    104|        }
   49|  4.13M|        mbi = (mbi << 7) | (i & 0x7f);
   50|  4.13M|    } while (i & 0x80);
  ------------------
  |  Branch (50:14): [True: 4.12M, False: 405]
  ------------------
   51|       |
   52|    405|    return mbi;
   53|    509|}
skipheader:
   86|    278|{
   87|    278|    int i;
   88|       |
   89|  45.7k|    do {
   90|  45.7k|        i = getin(in);
   91|  45.7k|        if (i < 0) {
  ------------------
  |  Branch (91:13): [True: 15, False: 45.7k]
  ------------------
   92|     15|            return (-1);
   93|     15|        }
   94|  45.7k|    } while (i & 0x80);
  ------------------
  |  Branch (94:14): [True: 45.4k, False: 263]
  ------------------
   95|       |
   96|    263|    return 0;
   97|    278|}
readwbmp:
  142|    287|{
  143|    287|    int row, col, byte, pel, pos;
  144|    287|    Wbmp *wbmp;
  145|       |
  146|    287|    if ((wbmp = (Wbmp *)gdMalloc(sizeof(Wbmp))) == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 287]
  ------------------
  147|      0|        return -1;
  148|      0|    }
  149|       |
  150|    287|    wbmp->type = getin(in);
  151|    287|    if (wbmp->type != 0) {
  ------------------
  |  Branch (151:9): [True: 9, False: 278]
  ------------------
  152|      9|        gdFree(wbmp);
  153|      9|        return -1;
  154|      9|    }
  155|       |
  156|    278|    if (skipheader(getin, in)) {
  ------------------
  |  Branch (156:9): [True: 15, False: 263]
  ------------------
  157|     15|        gdFree(wbmp);
  158|     15|        return -1;
  159|     15|    }
  160|       |
  161|    263|    wbmp->width = getmbi(getin, in);
  162|    263|    if (wbmp->width == -1) {
  ------------------
  |  Branch (162:9): [True: 17, False: 246]
  ------------------
  163|     17|        gdFree(wbmp);
  164|     17|        return -1;
  165|     17|    }
  166|       |
  167|    246|    wbmp->height = getmbi(getin, in);
  168|    246|    if (wbmp->height == -1) {
  ------------------
  |  Branch (168:9): [True: 87, False: 159]
  ------------------
  169|     87|        gdFree(wbmp);
  170|     87|        return -1;
  171|     87|    }
  172|       |
  173|       |#ifdef __DEBUG
  174|       |    printf("W: %d, H: %d\n", wbmp->width, wbmp->height);
  175|       |#endif
  176|       |
  177|    159|    if (overflow2(sizeof(int), wbmp->width) || overflow2(sizeof(int) * wbmp->width, wbmp->height)) {
  ------------------
  |  Branch (177:9): [True: 25, False: 134]
  |  Branch (177:48): [True: 62, False: 72]
  ------------------
  178|     87|        gdFree(wbmp);
  179|     87|        return -1;
  180|     87|    }
  181|       |
  182|     72|    if ((wbmp->bitmap = (int *)gdMalloc(sizeof(int) * wbmp->width * wbmp->height)) == NULL) {
  ------------------
  |  Branch (182:9): [True: 0, False: 72]
  ------------------
  183|      0|        gdFree(wbmp);
  184|      0|        return -1;
  185|      0|    }
  186|       |
  187|       |#ifdef __DEBUG
  188|       |    printf("DATA CONSTRUCTED\n");
  189|       |#endif
  190|       |
  191|     72|    pos = 0;
  192|   190k|    for (row = 0; row < wbmp->height; row++) {
  ------------------
  |  Branch (192:19): [True: 190k, False: 72]
  ------------------
  193|   404k|        for (col = 0; col < wbmp->width;) {
  ------------------
  |  Branch (193:23): [True: 213k, False: 190k]
  ------------------
  194|   213k|            byte = getin(in);
  195|       |
  196|  1.92M|            for (pel = 7; pel >= 0; pel--) {
  ------------------
  |  Branch (196:27): [True: 1.70M, False: 213k]
  ------------------
  197|  1.70M|                if (col++ < wbmp->width) {
  ------------------
  |  Branch (197:21): [True: 380k, False: 1.32M]
  ------------------
  198|   380k|                    if (byte & 1 << pel) {
  ------------------
  |  Branch (198:25): [True: 361k, False: 18.2k]
  ------------------
  199|   361k|                        wbmp->bitmap[pos] = WBMP_WHITE;
  ------------------
  |  |   31|   361k|#define WBMP_WHITE 1
  ------------------
  200|   361k|                    } else {
  201|  18.2k|                        wbmp->bitmap[pos] = WBMP_BLACK;
  ------------------
  |  |   32|  18.2k|#define WBMP_BLACK 0
  ------------------
  202|  18.2k|                    }
  203|   380k|                    pos++;
  204|   380k|                }
  205|  1.70M|            }
  206|   213k|        }
  207|   190k|    }
  208|       |
  209|     72|    *return_wbmp = wbmp;
  210|       |
  211|     72|    return 0;
  212|     72|}
freewbmp:
  265|     72|{
  266|     72|    gdFree(wbmp->bitmap);
  267|     72|    gdFree(wbmp);
  268|     72|}

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

