gd_error_ex:
  103|     86|{
  104|     86|    va_list args;
  105|       |
  106|     86|    va_start(args, format);
  107|     86|    _gd_error_ex(priority, format, args);
  108|       |    va_end(args);
  109|     86|}
gdImageCreate:
  162|     73|{
  163|     73|    int i;
  164|     73|    gdImagePtr im;
  165|       |
  166|     73|    if (overflow2(sx, sy)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 73]
  ------------------
  167|      0|        return NULL;
  168|      0|    }
  169|       |
  170|     73|    if (overflow2(sizeof(unsigned char *), sy)) {
  ------------------
  |  Branch (170:9): [True: 4, False: 69]
  ------------------
  171|      4|        return NULL;
  172|      4|    }
  173|     69|    if (overflow2(sizeof(unsigned char), sx)) {
  ------------------
  |  Branch (173:9): [True: 0, False: 69]
  ------------------
  174|      0|        return NULL;
  175|      0|    }
  176|       |
  177|     69|    im = (gdImage *)gdCalloc(1, sizeof(gdImage));
  178|     69|    if (!im) {
  ------------------
  |  Branch (178:9): [True: 0, False: 69]
  ------------------
  179|      0|        return NULL;
  180|      0|    }
  181|       |
  182|       |    /* Row-major ever since gd 1.3 */
  183|     69|    im->pixels = (unsigned char **)gdMalloc(sizeof(unsigned char *) * sy);
  184|     69|    if (!im->pixels) {
  ------------------
  |  Branch (184:9): [True: 0, False: 69]
  ------------------
  185|      0|        gdFree(im);
  186|      0|        return NULL;
  187|      0|    }
  188|       |
  189|     69|    im->polyInts = 0;
  190|     69|    im->polyAllocated = 0;
  191|     69|    im->brush = 0;
  192|     69|    im->tile = 0;
  193|     69|    im->style = 0;
  194|   124k|    for (i = 0; (i < sy); i++) {
  ------------------
  |  Branch (194:17): [True: 124k, False: 69]
  ------------------
  195|       |        /* Row-major ever since gd 1.3 */
  196|   124k|        im->pixels[i] = (unsigned char *)gdCalloc(sx, sizeof(unsigned char));
  197|   124k|        if (!im->pixels[i]) {
  ------------------
  |  Branch (197:13): [True: 0, False: 124k]
  ------------------
  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|   124k|    }
  206|     69|    im->sx = sx;
  207|     69|    im->sy = sy;
  208|     69|    im->colorsTotal = 0;
  209|     69|    im->transparent = (-1);
  210|     69|    im->interlace = 0;
  211|     69|    im->thick = 1;
  212|     69|    im->AA = 0;
  213|  17.7k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  17.7k|#define gdMaxColors 256
  ------------------
  |  Branch (213:17): [True: 17.6k, False: 69]
  ------------------
  214|  17.6k|        im->open[i] = 1;
  215|  17.6k|        im->red[i] = 0;
  216|  17.6k|        im->green[i] = 0;
  217|  17.6k|        im->blue[i] = 0;
  218|  17.6k|    };
  219|     69|    im->trueColor = 0;
  220|     69|    im->tpixels = 0;
  221|     69|    im->cx1 = 0;
  222|     69|    im->cy1 = 0;
  223|     69|    im->cx2 = im->sx - 1;
  224|     69|    im->cy2 = im->sy - 1;
  225|     69|    im->res_x = GD_RESOLUTION;
  ------------------
  |  | 8517|     69|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  226|     69|    im->res_y = GD_RESOLUTION;
  ------------------
  |  | 8517|     69|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  227|       |    im->interpolation = NULL;
  228|     69|    im->interpolation_id = GD_BILINEAR_FIXED;
  229|     69|    return im;
  230|     69|}
gdImageDestroy:
  340|     69|{
  341|     69|    int i;
  342|     69|    if (im->pixels) {
  ------------------
  |  Branch (342:9): [True: 69, False: 0]
  ------------------
  343|   124k|        for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (343:21): [True: 124k, False: 69]
  ------------------
  344|   124k|            gdFree(im->pixels[i]);
  345|   124k|        }
  346|     69|        gdFree(im->pixels);
  347|     69|    }
  348|     69|    if (im->tpixels) {
  ------------------
  |  Branch (348:9): [True: 0, False: 69]
  ------------------
  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|     69|    if (im->polyInts) {
  ------------------
  |  Branch (354:9): [True: 0, False: 69]
  ------------------
  355|      0|        gdFree(im->polyInts);
  356|      0|    }
  357|     69|    if (im->style) {
  ------------------
  |  Branch (357:9): [True: 0, False: 69]
  ------------------
  358|      0|        gdFree(im->style);
  359|      0|    }
  360|     69|    gdFree(im);
  361|     69|}
gdImageColorAllocate:
  544|    138|{
  545|    138|    return gdImageColorAllocateAlpha(im, r, g, b, gdAlphaOpaque);
  ------------------
  |  |  141|    138|#define gdAlphaOpaque 0
  ------------------
  546|    138|}
gdImageColorAllocateAlpha:
  550|    138|{
  551|    138|    int i;
  552|    138|    int ct = (-1);
  553|    138|    if (im->trueColor) {
  ------------------
  |  Branch (553:9): [True: 0, False: 138]
  ------------------
  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|    207|    for (i = 0; (i < (im->colorsTotal)); i++) {
  ------------------
  |  Branch (556:17): [True: 69, False: 138]
  ------------------
  557|     69|        if (im->open[i]) {
  ------------------
  |  Branch (557:13): [True: 0, False: 69]
  ------------------
  558|      0|            ct = i;
  559|      0|            break;
  560|      0|        }
  561|     69|    }
  562|    138|    if (ct == (-1)) {
  ------------------
  |  Branch (562:9): [True: 138, False: 0]
  ------------------
  563|    138|        ct = im->colorsTotal;
  564|    138|        if (ct == gdMaxColors) {
  ------------------
  |  |  117|    138|#define gdMaxColors 256
  ------------------
  |  Branch (564:13): [True: 0, False: 138]
  ------------------
  565|      0|            return -1;
  566|      0|        }
  567|    138|        im->colorsTotal++;
  568|    138|    }
  569|    138|    im->red[ct] = r;
  570|    138|    im->green[ct] = g;
  571|    138|    im->blue[ct] = b;
  572|    138|    im->alpha[ct] = a;
  573|    138|    im->open[ct] = 0;
  574|       |
  575|    138|    return ct;
  576|    138|}
gdImageSetPixel:
  966|   398k|{
  967|   398k|    int p;
  968|   398k|    switch (color) {
  969|      0|    case gdStyled:
  ------------------
  |  |  616|      0|#define gdStyled (-2)
  ------------------
  |  Branch (969:5): [True: 0, False: 398k]
  ------------------
  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: 398k]
  ------------------
  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: 398k]
  ------------------
  993|      0|        gdImageBrushApply(im, x, y);
  994|      0|        break;
  995|      0|    case gdTiled:
  ------------------
  |  |  619|      0|#define gdTiled (-5)
  ------------------
  |  Branch (995:5): [True: 0, False: 398k]
  ------------------
  996|      0|        gdImageTileApply(im, x, y);
  997|      0|        break;
  998|      0|    case gdAntiAliased:
  ------------------
  |  |  625|      0|#define gdAntiAliased (-7)
  ------------------
  |  Branch (998:5): [True: 0, False: 398k]
  ------------------
  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|   398k|    default:
  ------------------
  |  Branch (1003:5): [True: 398k, False: 0]
  ------------------
 1004|   398k|        if (gdImageBoundsSafeMacro(im, x, y)) {
  ------------------
  |  |   60|   398k|    (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
  |  |  ------------------
  |  |  |  Branch (60:9): [True: 0, False: 398k]
  |  |  |  Branch (60:30): [True: 0, False: 398k]
  |  |  |  Branch (60:53): [True: 0, False: 398k]
  |  |  |  Branch (60:74): [True: 0, False: 398k]
  |  |  ------------------
  ------------------
 1005|   398k|            if (im->trueColor) {
  ------------------
  |  Branch (1005:17): [True: 0, False: 398k]
  ------------------
 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|   398k|            } else {
 1023|   398k|                im->pixels[y][x] = color;
 1024|   398k|            }
 1025|   398k|        }
 1026|   398k|        break;
 1027|   398k|    }
 1028|   398k|}
gd.c:_gd_error_ex:
   88|     86|{
   89|     86|    if (gd_error_method) {
  ------------------
  |  Branch (89:9): [True: 86, False: 0]
  ------------------
   90|     86|        gd_error_method(priority, format, args);
   91|     86|    }
   92|     86|}
gd.c:gd_stderr_error:
   63|     86|{
   64|     86|    switch (priority) {
  ------------------
  |  Branch (64:13): [True: 86, False: 0]
  ------------------
   65|      0|    case GD_ERROR:
  ------------------
  |  |   37|      0|#define GD_ERROR LOG_ERR
  ------------------
  |  Branch (65:5): [True: 0, False: 86]
  ------------------
   66|      0|        fputs("GD Error: ", stderr);
   67|      0|        break;
   68|     86|    case GD_WARNING:
  ------------------
  |  |   38|     86|#define GD_WARNING LOG_WARNING
  ------------------
  |  Branch (68:5): [True: 86, False: 0]
  ------------------
   69|     86|        fputs("GD Warning: ", stderr);
   70|     86|        break;
   71|      0|    case GD_NOTICE:
  ------------------
  |  |   39|      0|#define GD_NOTICE LOG_NOTICE
  ------------------
  |  Branch (71:5): [True: 0, False: 86]
  ------------------
   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: 86]
  ------------------
   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: 86]
  ------------------
   78|      0|        fputs("GD Debug: ", stderr);
   79|      0|        break;
   80|     86|    }
   81|     86|    vfprintf(stderr, format, args);
   82|       |    fflush(stderr);
   83|     86|}

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

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

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

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

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

getmbi:
   40|    500|{
   41|    500|    unsigned int mbi = 0;
   42|    500|    int i;
   43|       |
   44|  4.11M|    do {
   45|  4.11M|        i = getin(in);
   46|  4.11M|        if (i < 0) {
  ------------------
  |  Branch (46:13): [True: 103, False: 4.11M]
  ------------------
   47|    103|            return (-1);
   48|    103|        }
   49|  4.11M|        mbi = (mbi << 7) | (i & 0x7f);
   50|  4.11M|    } while (i & 0x80);
  ------------------
  |  Branch (50:14): [True: 4.11M, False: 397]
  ------------------
   51|       |
   52|    397|    return mbi;
   53|    500|}
skipheader:
   86|    272|{
   87|    272|    int i;
   88|       |
   89|  55.8k|    do {
   90|  55.8k|        i = getin(in);
   91|  55.8k|        if (i < 0) {
  ------------------
  |  Branch (91:13): [True: 14, False: 55.8k]
  ------------------
   92|     14|            return (-1);
   93|     14|        }
   94|  55.8k|    } while (i & 0x80);
  ------------------
  |  Branch (94:14): [True: 55.6k, False: 258]
  ------------------
   95|       |
   96|    258|    return 0;
   97|    272|}
readwbmp:
  142|    281|{
  143|    281|    int row, col, byte, pel, pos;
  144|    281|    Wbmp *wbmp;
  145|       |
  146|    281|    if ((wbmp = (Wbmp *)gdMalloc(sizeof(Wbmp))) == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 281]
  ------------------
  147|      0|        return -1;
  148|      0|    }
  149|       |
  150|    281|    wbmp->type = getin(in);
  151|    281|    if (wbmp->type != 0) {
  ------------------
  |  Branch (151:9): [True: 9, False: 272]
  ------------------
  152|      9|        gdFree(wbmp);
  153|      9|        return -1;
  154|      9|    }
  155|       |
  156|    272|    if (skipheader(getin, in)) {
  ------------------
  |  Branch (156:9): [True: 14, False: 258]
  ------------------
  157|     14|        gdFree(wbmp);
  158|     14|        return -1;
  159|     14|    }
  160|       |
  161|    258|    wbmp->width = getmbi(getin, in);
  162|    258|    if (wbmp->width == -1) {
  ------------------
  |  Branch (162:9): [True: 16, False: 242]
  ------------------
  163|     16|        gdFree(wbmp);
  164|     16|        return -1;
  165|     16|    }
  166|       |
  167|    242|    wbmp->height = getmbi(getin, in);
  168|    242|    if (wbmp->height == -1) {
  ------------------
  |  Branch (168:9): [True: 87, False: 155]
  ------------------
  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|    155|    if (overflow2(sizeof(int), wbmp->width) || overflow2(sizeof(int) * wbmp->width, wbmp->height)) {
  ------------------
  |  Branch (177:9): [True: 12, False: 143]
  |  Branch (177:48): [True: 70, False: 73]
  ------------------
  178|     82|        gdFree(wbmp);
  179|     82|        return -1;
  180|     82|    }
  181|       |
  182|     73|    if ((wbmp->bitmap = (int *)gdMalloc(sizeof(int) * wbmp->width * wbmp->height)) == NULL) {
  ------------------
  |  Branch (182:9): [True: 0, False: 73]
  ------------------
  183|      0|        gdFree(wbmp);
  184|      0|        return -1;
  185|      0|    }
  186|       |
  187|       |#ifdef __DEBUG
  188|       |    printf("DATA CONSTRUCTED\n");
  189|       |#endif
  190|       |
  191|     73|    pos = 0;
  192|   186k|    for (row = 0; row < wbmp->height; row++) {
  ------------------
  |  Branch (192:19): [True: 186k, False: 73]
  ------------------
  193|   397k|        for (col = 0; col < wbmp->width;) {
  ------------------
  |  Branch (193:23): [True: 211k, False: 186k]
  ------------------
  194|   211k|            byte = getin(in);
  195|       |
  196|  1.89M|            for (pel = 7; pel >= 0; pel--) {
  ------------------
  |  Branch (196:27): [True: 1.68M, False: 211k]
  ------------------
  197|  1.68M|                if (col++ < wbmp->width) {
  ------------------
  |  Branch (197:21): [True: 459k, False: 1.22M]
  ------------------
  198|   459k|                    if (byte & 1 << pel) {
  ------------------
  |  Branch (198:25): [True: 418k, False: 41.0k]
  ------------------
  199|   418k|                        wbmp->bitmap[pos] = WBMP_WHITE;
  ------------------
  |  |   31|   418k|#define WBMP_WHITE 1
  ------------------
  200|   418k|                    } else {
  201|  41.0k|                        wbmp->bitmap[pos] = WBMP_BLACK;
  ------------------
  |  |   32|  41.0k|#define WBMP_BLACK 0
  ------------------
  202|  41.0k|                    }
  203|   459k|                    pos++;
  204|   459k|                }
  205|  1.68M|            }
  206|   211k|        }
  207|   186k|    }
  208|       |
  209|     73|    *return_wbmp = wbmp;
  210|       |
  211|     73|    return 0;
  212|     73|}
freewbmp:
  265|     73|{
  266|     73|    gdFree(wbmp->bitmap);
  267|     73|    gdFree(wbmp);
  268|     73|}

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

