gd_error_ex:
  103|     33|{
  104|     33|    va_list args;
  105|       |
  106|     33|    va_start(args, format);
  107|     33|    _gd_error_ex(priority, format, args);
  108|       |    va_end(args);
  109|     33|}
gdImageCreate:
  162|    446|{
  163|    446|    int i;
  164|    446|    gdImagePtr im;
  165|       |
  166|    446|    if (overflow2(sx, sy)) {
  ------------------
  |  Branch (166:9): [True: 28, False: 418]
  ------------------
  167|     28|        return NULL;
  168|     28|    }
  169|       |
  170|    418|    if (overflow2(sizeof(unsigned char *), sy)) {
  ------------------
  |  Branch (170:9): [True: 5, False: 413]
  ------------------
  171|      5|        return NULL;
  172|      5|    }
  173|    413|    if (overflow2(sizeof(unsigned char), sx)) {
  ------------------
  |  Branch (173:9): [True: 0, False: 413]
  ------------------
  174|      0|        return NULL;
  175|      0|    }
  176|       |
  177|    413|    im = (gdImage *)gdCalloc(1, sizeof(gdImage));
  178|    413|    if (!im) {
  ------------------
  |  Branch (178:9): [True: 0, False: 413]
  ------------------
  179|      0|        return NULL;
  180|      0|    }
  181|       |
  182|       |    /* Row-major ever since gd 1.3 */
  183|    413|    im->pixels = (unsigned char **)gdMalloc(sizeof(unsigned char *) * sy);
  184|    413|    if (!im->pixels) {
  ------------------
  |  Branch (184:9): [True: 0, False: 413]
  ------------------
  185|      0|        gdFree(im);
  186|      0|        return NULL;
  187|      0|    }
  188|       |
  189|    413|    im->polyInts = 0;
  190|    413|    im->polyAllocated = 0;
  191|    413|    im->brush = 0;
  192|    413|    im->tile = 0;
  193|    413|    im->style = 0;
  194|   531k|    for (i = 0; (i < sy); i++) {
  ------------------
  |  Branch (194:17): [True: 531k, False: 413]
  ------------------
  195|       |        /* Row-major ever since gd 1.3 */
  196|   531k|        im->pixels[i] = (unsigned char *)gdCalloc(sx, sizeof(unsigned char));
  197|   531k|        if (!im->pixels[i]) {
  ------------------
  |  Branch (197:13): [True: 0, False: 531k]
  ------------------
  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|   531k|    }
  206|    413|    im->sx = sx;
  207|    413|    im->sy = sy;
  208|    413|    im->colorsTotal = 0;
  209|    413|    im->transparent = (-1);
  210|    413|    im->interlace = 0;
  211|    413|    im->thick = 1;
  212|    413|    im->AA = 0;
  213|   106k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|   106k|#define gdMaxColors 256
  ------------------
  |  Branch (213:17): [True: 105k, False: 413]
  ------------------
  214|   105k|        im->open[i] = 1;
  215|   105k|        im->red[i] = 0;
  216|   105k|        im->green[i] = 0;
  217|   105k|        im->blue[i] = 0;
  218|   105k|    };
  219|    413|    im->trueColor = 0;
  220|    413|    im->tpixels = 0;
  221|    413|    im->cx1 = 0;
  222|    413|    im->cy1 = 0;
  223|    413|    im->cx2 = im->sx - 1;
  224|    413|    im->cy2 = im->sy - 1;
  225|    413|    im->res_x = GD_RESOLUTION;
  ------------------
  |  | 8130|    413|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  226|    413|    im->res_y = GD_RESOLUTION;
  ------------------
  |  | 8130|    413|#define GD_RESOLUTION 96 /* pixels per inch */
  ------------------
  227|       |    im->interpolation = NULL;
  228|    413|    im->interpolation_id = GD_BILINEAR_FIXED;
  229|    413|    return im;
  230|    413|}
gdImageDestroy:
  340|    413|{
  341|    413|    int i;
  342|    413|    if (im->pixels) {
  ------------------
  |  Branch (342:9): [True: 413, False: 0]
  ------------------
  343|   531k|        for (i = 0; (i < im->sy); i++) {
  ------------------
  |  Branch (343:21): [True: 531k, False: 413]
  ------------------
  344|   531k|            gdFree(im->pixels[i]);
  345|   531k|        }
  346|    413|        gdFree(im->pixels);
  347|    413|    }
  348|    413|    if (im->tpixels) {
  ------------------
  |  Branch (348:9): [True: 0, False: 413]
  ------------------
  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|    413|    if (im->polyInts) {
  ------------------
  |  Branch (354:9): [True: 0, False: 413]
  ------------------
  355|      0|        gdFree(im->polyInts);
  356|      0|    }
  357|    413|    if (im->style) {
  ------------------
  |  Branch (357:9): [True: 0, False: 413]
  ------------------
  358|      0|        gdFree(im->style);
  359|      0|    }
  360|    413|    gdFree(im);
  361|    413|}
gdImageColorTransparent:
  644|     16|{
  645|       |    // Reset ::transparent
  646|     16|    if (color == -1) {
  ------------------
  |  Branch (646:9): [True: 0, False: 16]
  ------------------
  647|      0|        im->transparent = -1;
  648|      0|        return;
  649|      0|    }
  650|     16|    if (color < -1) {
  ------------------
  |  Branch (650:9): [True: 0, False: 16]
  ------------------
  651|      0|        return;
  652|      0|    }
  653|       |
  654|     16|    if (im->trueColor) {
  ------------------
  |  Branch (654:9): [True: 0, False: 16]
  ------------------
  655|      0|        im->transparent = color;
  656|      0|        return;
  657|      0|    }
  658|       |
  659|       |    // Palette Image
  660|     16|    if (color >= gdMaxColors) {
  ------------------
  |  |  117|     16|#define gdMaxColors 256
  ------------------
  |  Branch (660:9): [True: 0, False: 16]
  ------------------
  661|      0|        return;
  662|      0|    }
  663|     16|    if (im->transparent != -1) {
  ------------------
  |  Branch (663:9): [True: 0, False: 16]
  ------------------
  664|      0|        im->alpha[im->transparent] = gdAlphaOpaque;
  ------------------
  |  |  141|      0|#define gdAlphaOpaque 0
  ------------------
  665|      0|    }
  666|     16|    im->alpha[color] = gdAlphaTransparent;
  ------------------
  |  |  142|     16|#define gdAlphaTransparent 127
  ------------------
  667|     16|    im->transparent = color;
  668|     16|}
gdImageSetPixel:
  966|   282k|{
  967|   282k|    int p;
  968|   282k|    switch (color) {
  969|      0|    case gdStyled:
  ------------------
  |  |  628|      0|#define gdStyled (-2)
  ------------------
  |  Branch (969:5): [True: 0, False: 282k]
  ------------------
  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)) {
  ------------------
  |  |  635|      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:
  ------------------
  |  |  630|      0|#define gdStyledBrushed (-4)
  ------------------
  |  Branch (981:5): [True: 0, False: 282k]
  ------------------
  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)) {
  ------------------
  |  |  635|      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);
  ------------------
  |  |  629|      0|#define gdBrushed (-3)
  ------------------
  989|      0|        }
  990|      0|        im->stylePos = im->stylePos % im->styleLength;
  991|      0|        break;
  992|      0|    case gdBrushed:
  ------------------
  |  |  629|      0|#define gdBrushed (-3)
  ------------------
  |  Branch (992:5): [True: 0, False: 282k]
  ------------------
  993|      0|        gdImageBrushApply(im, x, y);
  994|      0|        break;
  995|      0|    case gdTiled:
  ------------------
  |  |  631|      0|#define gdTiled (-5)
  ------------------
  |  Branch (995:5): [True: 0, False: 282k]
  ------------------
  996|      0|        gdImageTileApply(im, x, y);
  997|      0|        break;
  998|      0|    case gdAntiAliased:
  ------------------
  |  |  637|      0|#define gdAntiAliased (-7)
  ------------------
  |  Branch (998:5): [True: 0, False: 282k]
  ------------------
  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|   282k|    default:
  ------------------
  |  Branch (1003:5): [True: 282k, False: 0]
  ------------------
 1004|   282k|        if (gdImageBoundsSafeMacro(im, x, y)) {
  ------------------
  |  |   58|   282k|    (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
  |  |  ------------------
  |  |  |  Branch (58:9): [True: 0, False: 282k]
  |  |  |  Branch (58:30): [True: 0, False: 282k]
  |  |  |  Branch (58:53): [True: 0, False: 282k]
  |  |  |  Branch (58:74): [True: 0, False: 282k]
  |  |  ------------------
  ------------------
 1005|   282k|            if (im->trueColor) {
  ------------------
  |  Branch (1005:17): [True: 0, False: 282k]
  ------------------
 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|   282k|            } else {
 1023|   282k|                im->pixels[y][x] = color;
 1024|   282k|            }
 1025|   282k|        }
 1026|   282k|        break;
 1027|   282k|    }
 1028|   282k|}
gd.c:_gd_error_ex:
   88|     33|{
   89|     33|    if (gd_error_method) {
  ------------------
  |  Branch (89:9): [True: 33, False: 0]
  ------------------
   90|     33|        gd_error_method(priority, format, args);
   91|     33|    }
   92|     33|}
gd.c:gd_stderr_error:
   63|     33|{
   64|     33|    switch (priority) {
  ------------------
  |  Branch (64:13): [True: 33, False: 0]
  ------------------
   65|      0|    case GD_ERROR:
  ------------------
  |  |   37|      0|#define GD_ERROR LOG_ERR
  ------------------
  |  Branch (65:5): [True: 0, False: 33]
  ------------------
   66|      0|        fputs("GD Error: ", stderr);
   67|      0|        break;
   68|     33|    case GD_WARNING:
  ------------------
  |  |   38|     33|#define GD_WARNING LOG_WARNING
  ------------------
  |  Branch (68:5): [True: 33, False: 0]
  ------------------
   69|     33|        fputs("GD Warning: ", stderr);
   70|     33|        break;
   71|      0|    case GD_NOTICE:
  ------------------
  |  |   39|      0|#define GD_NOTICE LOG_NOTICE
  ------------------
  |  Branch (71:5): [True: 0, False: 33]
  ------------------
   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: 33]
  ------------------
   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: 33]
  ------------------
   78|      0|        fputs("GD Debug: ", stderr);
   79|      0|        break;
   80|     33|    }
   81|     33|    vfprintf(stderr, format, args);
   82|       |    fflush(stderr);
   83|     33|}

gdImageCreateFromGifPtr:
  881|    811|{
  882|    811|    gdImagePtr im;
  883|    811|    gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
  884|    811|    if (!in) {
  ------------------
  |  Branch (884:9): [True: 0, False: 811]
  ------------------
  885|      0|        return 0;
  886|      0|    }
  887|    811|    im = gdImageCreateFromGifCtx(in);
  888|    811|    in->gd_free(in);
  889|    811|    return im;
  890|    811|}
gdImageCreateFromGifCtx:
  893|    811|{
  894|    811|    int BitPixel;
  895|       |#if 0
  896|       |	int ColorResolution;
  897|       |	int Background;
  898|       |	int AspectRatio;
  899|       |#endif
  900|    811|    int Transparent = (-1);
  901|    811|    unsigned char buf[16];
  902|    811|    unsigned char c;
  903|    811|    unsigned char ColorMap[3][MAXCOLORMAPSIZE];
  904|    811|    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
  905|    811|    int imw, imh, screen_width, screen_height;
  906|    811|    int useGlobalColormap;
  907|    811|    int bitPixel, i;
  908|       |    /*1.4//int             imageCount = 0; */
  909|       |    /* 2.0.28: threadsafe storage */
  910|    811|    int ZeroDataBlock = FALSE;
  ------------------
  |  |   43|    811|#define FALSE 0
  ------------------
  911|    811|    int haveGlobalColormap;
  912|       |
  913|    811|    gdImagePtr im = 0;
  914|       |
  915|    811|    memset(ColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   40|    811|#define MAXCOLORMAPSIZE 256
  ------------------
  916|    811|    memset(localColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   40|    811|#define MAXCOLORMAPSIZE 256
  ------------------
  917|       |
  918|    811|    if (!ReadOK(fd, buf, 6)) {
  ------------------
  |  |   56|    811|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (918:9): [True: 4, False: 807]
  ------------------
  919|      4|        return 0;
  920|      4|    }
  921|       |
  922|    807|    if (strncmp((char *)buf, "GIF", 3) != 0) {
  ------------------
  |  Branch (922:9): [True: 32, False: 775]
  ------------------
  923|     32|        return 0;
  924|     32|    }
  925|       |
  926|    775|    if (memcmp((char *)buf + 3, "87a", 3) == 0) {
  ------------------
  |  Branch (926:9): [True: 252, False: 523]
  ------------------
  927|       |        /* GIF87a */
  928|    523|    } else if (memcmp((char *)buf + 3, "89a", 3) == 0) {
  ------------------
  |  Branch (928:16): [True: 461, False: 62]
  ------------------
  929|       |        /* GIF89a */
  930|    461|    } else {
  931|     62|        return 0;
  932|     62|    }
  933|       |
  934|    713|    if (!ReadOK(fd, buf, 7)) {
  ------------------
  |  |   56|    713|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (934:9): [True: 6, False: 707]
  ------------------
  935|      6|        return 0;
  936|      6|    }
  937|       |
  938|    707|    BitPixel = 2 << (buf[4] & 0x07);
  939|       |#if 0
  940|       |	ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
  941|       |	Background = buf[5];
  942|       |	AspectRatio = buf[6];
  943|       |#endif
  944|    707|    screen_width = imw = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   58|    707|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  945|    707|    screen_height = imh = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   58|    707|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  946|       |
  947|    707|    haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
  ------------------
  |  |   54|    707|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  948|    707|    if (haveGlobalColormap) {
  ------------------
  |  Branch (948:9): [True: 22, False: 685]
  ------------------
  949|     22|        if (ReadColorMap(fd, BitPixel, ColorMap)) {
  ------------------
  |  Branch (949:13): [True: 19, False: 3]
  ------------------
  950|     19|            return 0;
  951|     19|        }
  952|     22|    }
  953|       |
  954|  4.90M|    for (;;) {
  955|  4.90M|        int top, left;
  956|  4.90M|        int width, height;
  957|       |
  958|  4.90M|        if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   56|  4.90M|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (958:13): [True: 198, False: 4.90M]
  ------------------
  959|    198|            return 0;
  960|    198|        }
  961|       |
  962|  4.90M|        if (c == ';') { /* GIF terminator */
  ------------------
  |  Branch (962:13): [True: 2, False: 4.90M]
  ------------------
  963|      2|            goto terminated;
  964|      2|        }
  965|       |
  966|  4.90M|        if (c == '!') { /* Extension */
  ------------------
  |  Branch (966:13): [True: 17.9k, False: 4.88M]
  ------------------
  967|  17.9k|            if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   56|  17.9k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (967:17): [True: 1, False: 17.9k]
  ------------------
  968|      1|                return 0;
  969|      1|            }
  970|       |
  971|  17.9k|            DoExtension(fd, c, &Transparent, &ZeroDataBlock);
  972|  17.9k|            continue;
  973|  17.9k|        }
  974|       |
  975|  4.88M|        if (c != ',') { /* Not a valid start character */
  ------------------
  |  Branch (975:13): [True: 4.88M, False: 487]
  ------------------
  976|  4.88M|            continue;
  977|  4.88M|        }
  978|       |
  979|       |        /*1.4//++imageCount; */
  980|       |
  981|    487|        if (!ReadOK(fd, buf, 9)) {
  ------------------
  |  |   56|    487|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (981:13): [True: 5, False: 482]
  ------------------
  982|      5|            return 0;
  983|      5|        }
  984|       |
  985|    482|        useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
  ------------------
  |  |   54|    482|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  986|       |
  987|    482|        bitPixel = 1 << ((buf[8] & 0x07) + 1);
  988|    482|        left = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   58|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  989|    482|        top = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   58|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  990|    482|        width = LM_to_uint(buf[4], buf[5]);
  ------------------
  |  |   58|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  991|    482|        height = LM_to_uint(buf[6], buf[7]);
  ------------------
  |  |   58|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
  992|       |
  993|    482|        if (((left + width) > screen_width) || ((top + height) > screen_height)) {
  ------------------
  |  Branch (993:13): [True: 19, False: 463]
  |  Branch (993:48): [True: 17, False: 446]
  ------------------
  994|     36|            if (VERBOSE) {
  ------------------
  |  |   36|     36|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (36:17): [Folded, False: 36]
  |  |  ------------------
  ------------------
  995|      0|                printf("Frame is not confined to screen dimension.\n");
  996|      0|            }
  997|     36|            return 0;
  998|     36|        }
  999|       |
 1000|    446|        if (!(im = gdImageCreate(width, height))) {
  ------------------
  |  Branch (1000:13): [True: 33, False: 413]
  ------------------
 1001|     33|            return 0;
 1002|     33|        }
 1003|       |
 1004|    413|        im->interlace = BitSet(buf[8], INTERLACE);
  ------------------
  |  |   54|    413|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1005|    413|        if (!useGlobalColormap) {
  ------------------
  |  Branch (1005:13): [True: 19, False: 394]
  ------------------
 1006|     19|            if (ReadColorMap(fd, bitPixel, localColorMap)) {
  ------------------
  |  Branch (1006:17): [True: 14, False: 5]
  ------------------
 1007|     14|                gdImageDestroy(im);
 1008|     14|                return 0;
 1009|     14|            }
 1010|       |
 1011|       |            /* Legacy gdImageCreateFromGif* is intentionally tolerant of
 1012|       |             * out-of-palette LZW results and maps them to color 0. The newer
 1013|       |             * iterator API passes the actual color table size and rejects those
 1014|       |             * malformed frames instead.
 1015|       |             */
 1016|      5|            if (!ReadImage(im, fd, width, height, localColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   54|      5|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1016:17): [True: 2, False: 3]
  ------------------
 1017|      5|                           &ZeroDataBlock)) {
 1018|      2|                gdImageDestroy(im);
 1019|      2|                return 0;
 1020|      2|            }
 1021|    394|        } else {
 1022|    394|            if (!haveGlobalColormap) {
  ------------------
  |  Branch (1022:17): [True: 393, False: 1]
  ------------------
 1023|       |                // Still a valid gif, apply simple default palette as per spec
 1024|    393|                ColorMap[CM_RED][1] = 0xff;
  ------------------
  |  |   45|    393|#define CM_RED 0
  ------------------
 1025|    393|                ColorMap[CM_GREEN][1] = 0xff;
  ------------------
  |  |   46|    393|#define CM_GREEN 1
  ------------------
 1026|    393|                ColorMap[CM_BLUE][1] = 0xff;
  ------------------
  |  |   47|    393|#define CM_BLUE 2
  ------------------
 1027|    393|            }
 1028|       |
 1029|       |            /* Keep legacy tolerance here as above; strict validation is used by
 1030|       |             * the animated GIF iterator.
 1031|       |             */
 1032|    394|            if (!ReadImage(im, fd, width, height, ColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   54|    394|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1032:17): [True: 25, False: 369]
  ------------------
 1033|    394|                           &ZeroDataBlock)) {
 1034|     25|                gdImageDestroy(im);
 1035|     25|                return 0;
 1036|     25|            }
 1037|    394|        }
 1038|       |
 1039|    372|        if (Transparent != (-1)) {
  ------------------
  |  Branch (1039:13): [True: 16, False: 356]
  ------------------
 1040|     16|            gdImageColorTransparent(im, Transparent);
 1041|     16|        }
 1042|       |
 1043|    372|        goto terminated;
 1044|    413|    }
 1045|       |
 1046|    374|terminated:
 1047|       |    /* Terminator before any image was declared! */
 1048|    374|    if (!im) {
  ------------------
  |  Branch (1048:9): [True: 2, False: 372]
  ------------------
 1049|      2|        return 0;
 1050|      2|    }
 1051|       |
 1052|       |    /* Check for open colors at the end, so
 1053|       |     * we can reduce colorsTotal and ultimately
 1054|       |     * BitsPerPixel */
 1055|  77.2k|    for (i = im->colorsTotal - 1; i >= 0; i--) {
  ------------------
  |  Branch (1055:35): [True: 77.2k, False: 43]
  ------------------
 1056|  77.2k|        if (im->open[i]) {
  ------------------
  |  Branch (1056:13): [True: 76.9k, False: 329]
  ------------------
 1057|  76.9k|            im->colorsTotal--;
 1058|  76.9k|        } else {
 1059|    329|            break;
 1060|    329|        }
 1061|  77.2k|    }
 1062|       |
 1063|    372|    if (!im->colorsTotal) {
  ------------------
  |  Branch (1063:9): [True: 43, False: 329]
  ------------------
 1064|     43|        gdImageDestroy(im);
 1065|     43|        return 0;
 1066|     43|    }
 1067|       |
 1068|    329|    return im;
 1069|    372|}
gd_gif_in.c:GetDataBlock:
 1139|   135k|{
 1140|   135k|    int rv, i;
 1141|       |
 1142|   135k|    rv = GetDataBlock_(fd, buf, ZeroDataBlockP);
 1143|       |
 1144|   135k|    if (VERBOSE) {
  ------------------
  |  |   36|   135k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (36:17): [Folded, False: 135k]
  |  |  ------------------
  ------------------
 1145|      0|        printf("[GetDataBlock returning %d", rv);
 1146|      0|        if (rv > 0) {
  ------------------
  |  Branch (1146:13): [True: 0, False: 0]
  ------------------
 1147|      0|            printf(":");
 1148|      0|            for (i = 0; i < rv; i++) {
  ------------------
  |  Branch (1148:25): [True: 0, False: 0]
  ------------------
 1149|      0|                printf(" %02x", buf[i]);
 1150|      0|            }
 1151|      0|        }
 1152|      0|        printf("]\n");
 1153|      0|    }
 1154|       |
 1155|   135k|    return rv;
 1156|   135k|}
gd_gif_in.c:GetDataBlock_:
 1122|   135k|{
 1123|   135k|    unsigned char count;
 1124|       |
 1125|   135k|    if (!ReadOK(fd, &count, 1)) {
  ------------------
  |  |   56|   135k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1125:9): [True: 454, False: 134k]
  ------------------
 1126|    454|        return -1;
 1127|    454|    }
 1128|       |
 1129|   134k|    *ZeroDataBlockP = count == 0;
 1130|       |
 1131|   134k|    if ((count != 0) && (!ReadOK(fd, buf, count))) {
  ------------------
  |  |   56|   114k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1131:9): [True: 114k, False: 20.5k]
  |  Branch (1131:25): [True: 79, False: 114k]
  ------------------
 1132|     79|        return -1;
 1133|     79|    }
 1134|       |
 1135|   134k|    return count;
 1136|   134k|}
gd_gif_in.c:ReadColorMap:
 1072|     41|{
 1073|     41|    int i;
 1074|     41|    unsigned char rgb[3];
 1075|       |
 1076|    663|    for (i = 0; i < number; ++i) {
  ------------------
  |  Branch (1076:17): [True: 655, False: 8]
  ------------------
 1077|    655|        if (!ReadOK(fd, rgb, sizeof(rgb))) {
  ------------------
  |  |   56|    655|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1077:13): [True: 33, False: 622]
  ------------------
 1078|     33|            return TRUE;
  ------------------
  |  |   42|     33|#define TRUE 1
  ------------------
 1079|     33|        }
 1080|       |
 1081|    622|        buffer[CM_RED][i] = rgb[0];
  ------------------
  |  |   45|    622|#define CM_RED 0
  ------------------
 1082|    622|        buffer[CM_GREEN][i] = rgb[1];
  ------------------
  |  |   46|    622|#define CM_GREEN 1
  ------------------
 1083|    622|        buffer[CM_BLUE][i] = rgb[2];
  ------------------
  |  |   47|    622|#define CM_BLUE 2
  ------------------
 1084|    622|    }
 1085|       |
 1086|      8|    return FALSE;
  ------------------
  |  |   43|      8|#define FALSE 0
  ------------------
 1087|     41|}
gd_gif_in.c:DoExtension:
 1090|  17.9k|{
 1091|  17.9k|    unsigned char buf[256];
 1092|       |
 1093|  17.9k|    switch (label) {
 1094|  14.7k|    case 0xf9:             /* Graphic Control Extension */
  ------------------
  |  Branch (1094:5): [True: 14.7k, False: 3.22k]
  ------------------
 1095|  14.7k|        memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
 1096|  14.7k|        (void)GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP);
 1097|       |#if 0
 1098|       |		Gif89.disposal  = (buf[0] >> 2) & 0x7;
 1099|       |		Gif89.inputFlag = (buf[0] >> 1) & 0x1;
 1100|       |		Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
 1101|       |#endif
 1102|  14.7k|        if ((buf[0] & 0x1) != 0) {
  ------------------
  |  Branch (1102:13): [True: 9.42k, False: 5.35k]
  ------------------
 1103|  9.42k|            *Transparent = buf[3];
 1104|  9.42k|        }
 1105|       |
 1106|  45.3k|        while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1106:16): [True: 30.5k, False: 14.7k]
  ------------------
 1107|  30.5k|            ;
 1108|       |
 1109|  14.7k|        return FALSE;
  ------------------
  |  |   43|  14.7k|#define FALSE 0
  ------------------
 1110|       |
 1111|  3.22k|    default:
  ------------------
  |  Branch (1111:5): [True: 3.22k, False: 14.7k]
  ------------------
 1112|  3.22k|        break;
 1113|  17.9k|    }
 1114|       |
 1115|  70.1k|    while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1115:12): [True: 66.9k, False: 3.22k]
  ------------------
 1116|  66.9k|        ;
 1117|       |
 1118|  3.22k|    return FALSE;
  ------------------
  |  |   43|  3.22k|#define FALSE 0
  ------------------
 1119|  17.9k|}
gd_gif_in.c:ReadImage:
 1386|    399|{
 1387|    399|    unsigned char c;
 1388|    399|    int xpos = 0, ypos = 0, pass = 0;
 1389|    399|    int v, i;
 1390|    399|    LZW_STATIC_DATA sd;
 1391|       |
 1392|       |    /* Initialize the Compression routines */
 1393|    399|    if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   56|    399|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1393:9): [True: 21, False: 378]
  ------------------
 1394|     21|        return 0;
 1395|     21|    }
 1396|       |
 1397|    378|    if (c > MAX_LWZ_BITS) {
  ------------------
  |  |   49|    378|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1397:9): [True: 6, False: 372]
  ------------------
 1398|      6|        return 0;
 1399|      6|    }
 1400|       |
 1401|       |    /* Stash the color map into the image */
 1402|  95.6k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  95.6k|#define gdMaxColors 256
  ------------------
  |  Branch (1402:17): [True: 95.2k, False: 372]
  ------------------
 1403|  95.2k|        im->red[i] = cmap[CM_RED][i];
  ------------------
  |  |   45|  95.2k|#define CM_RED 0
  ------------------
 1404|  95.2k|        im->green[i] = cmap[CM_GREEN][i];
  ------------------
  |  |   46|  95.2k|#define CM_GREEN 1
  ------------------
 1405|  95.2k|        im->blue[i] = cmap[CM_BLUE][i];
  ------------------
  |  |   47|  95.2k|#define CM_BLUE 2
  ------------------
 1406|  95.2k|        im->open[i] = 1;
 1407|  95.2k|    }
 1408|       |
 1409|       |    /* Many (perhaps most) of these colors will remain marked open. */
 1410|    372|    im->colorsTotal = gdMaxColors;
  ------------------
  |  |  117|    372|#define gdMaxColors 256
  ------------------
 1411|    372|    if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
  ------------------
  |  |   42|    372|#define TRUE 1
  ------------------
  |  Branch (1411:9): [True: 0, False: 372]
  ------------------
 1412|      0|        return 0;
 1413|      0|    }
 1414|       |
 1415|       |    /*
 1416|       |    **  If this is an "uninteresting picture" ignore it.
 1417|       |    **  REMOVED For 1.4
 1418|       |    */
 1419|       |    /*if (ignore) { */
 1420|       |    /*        while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */
 1421|       |    /*                ; */
 1422|       |    /*        return; */
 1423|       |    /*} */
 1424|       |
 1425|   282k|    while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   43|   282k|#define FALSE 0
  ------------------
  |  Branch (1425:12): [True: 282k, False: 356]
  ------------------
 1426|   282k|        if (colorCount > 0 && v >= colorCount) {
  ------------------
  |  Branch (1426:13): [True: 0, False: 282k]
  |  Branch (1426:31): [True: 0, False: 0]
  ------------------
 1427|      0|            return 0;
 1428|      0|        }
 1429|   282k|        if (v >= gdMaxColors) {
  ------------------
  |  |  117|   282k|#define gdMaxColors 256
  ------------------
  |  Branch (1429:13): [True: 94.8k, False: 187k]
  ------------------
 1430|  94.8k|            v = 0;
 1431|  94.8k|        }
 1432|       |
 1433|       |        /* This how we recognize which colors are actually used. */
 1434|   282k|        if (im->open[v]) {
  ------------------
  |  Branch (1434:13): [True: 2.40k, False: 279k]
  ------------------
 1435|  2.40k|            im->open[v] = 0;
 1436|  2.40k|        }
 1437|       |
 1438|   282k|        gdImageSetPixel(im, xpos, ypos, v);
 1439|       |
 1440|   282k|        ++xpos;
 1441|   282k|        if (xpos == len) {
  ------------------
  |  Branch (1441:13): [True: 28.6k, False: 253k]
  ------------------
 1442|  28.6k|            xpos = 0;
 1443|  28.6k|            if (interlace) {
  ------------------
  |  Branch (1443:17): [True: 22.4k, False: 6.22k]
  ------------------
 1444|  22.4k|                switch (pass) {
  ------------------
  |  Branch (1444:25): [True: 22.4k, False: 0]
  ------------------
 1445|  7.49k|                case 0:
  ------------------
  |  Branch (1445:17): [True: 7.49k, False: 14.9k]
  ------------------
 1446|  10.8k|                case 1:
  ------------------
  |  Branch (1446:17): [True: 3.33k, False: 19.0k]
  ------------------
 1447|  10.8k|                    ypos += 8;
 1448|  10.8k|                    break;
 1449|  6.11k|                case 2:
  ------------------
  |  Branch (1449:17): [True: 6.11k, False: 16.3k]
  ------------------
 1450|  6.11k|                    ypos += 4;
 1451|  6.11k|                    break;
 1452|  5.48k|                case 3:
  ------------------
  |  Branch (1452:17): [True: 5.48k, False: 16.9k]
  ------------------
 1453|  5.48k|                    ypos += 2;
 1454|  5.48k|                    break;
 1455|  22.4k|                }
 1456|       |
 1457|  22.4k|                if (ypos >= height) {
  ------------------
  |  Branch (1457:21): [True: 155, False: 22.2k]
  ------------------
 1458|    155|                    ++pass;
 1459|    155|                    switch (pass) {
 1460|     60|                    case 1:
  ------------------
  |  Branch (1460:21): [True: 60, False: 95]
  ------------------
 1461|     60|                        ypos = 4;
 1462|     60|                        break;
 1463|     48|                    case 2:
  ------------------
  |  Branch (1463:21): [True: 48, False: 107]
  ------------------
 1464|     48|                        ypos = 2;
 1465|     48|                        break;
 1466|     35|                    case 3:
  ------------------
  |  Branch (1466:21): [True: 35, False: 120]
  ------------------
 1467|     35|                        ypos = 1;
 1468|     35|                        break;
 1469|     12|                    default:
  ------------------
  |  Branch (1469:21): [True: 12, False: 143]
  ------------------
 1470|     12|                        goto fini;
 1471|    155|                    }
 1472|    155|                }
 1473|  22.4k|            } else {
 1474|  6.22k|                ++ypos;
 1475|  6.22k|            }
 1476|  28.6k|        }
 1477|       |
 1478|   282k|        if (ypos >= height) {
  ------------------
  |  Branch (1478:13): [True: 4, False: 282k]
  ------------------
 1479|      4|            break;
 1480|      4|        }
 1481|   282k|    }
 1482|       |
 1483|    372|fini:
 1484|    372|    if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >= 0) {
  ------------------
  |  |   43|    372|#define FALSE 0
  ------------------
  |  Branch (1484:9): [True: 29, False: 343]
  ------------------
 1485|       |        /* Ignore extra */
 1486|     29|    }
 1487|    372|    return 1;
 1488|    372|}
gd_gif_in.c:LWZReadByte:
 1372|   283k|{
 1373|   283k|    int rv;
 1374|       |
 1375|   283k|    rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
 1376|       |
 1377|   283k|    if (VERBOSE) {
  ------------------
  |  |   36|   283k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (36:17): [Folded, False: 283k]
  |  |  ------------------
  ------------------
 1378|      0|        printf("[LWZReadByte(,%d,%d) returning %d]\n", flag, input_code_size, rv);
 1379|      0|    }
 1380|       |
 1381|   283k|    return rv;
 1382|   283k|}
gd_gif_in.c:LWZReadByte_:
 1234|   283k|{
 1235|   283k|    int code, incode, i;
 1236|       |
 1237|   283k|    if (flag) {
  ------------------
  |  Branch (1237:9): [True: 372, False: 282k]
  ------------------
 1238|    372|        sd->set_code_size = input_code_size;
 1239|    372|        sd->code_size = sd->set_code_size + 1;
 1240|    372|        sd->clear_code = 1 << sd->set_code_size;
 1241|    372|        sd->end_code = sd->clear_code + 1;
 1242|    372|        sd->max_code_size = 2 * sd->clear_code;
 1243|    372|        sd->max_code = sd->clear_code + 2;
 1244|       |
 1245|    372|        GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
  ------------------
  |  |   42|    372|#define TRUE 1
  ------------------
 1246|       |
 1247|    372|        sd->fresh = TRUE;
  ------------------
  |  |   42|    372|#define TRUE 1
  ------------------
 1248|       |
 1249|   353k|        for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1249:21): [True: 352k, False: 372]
  ------------------
 1250|   352k|            sd->table[0][i] = 0;
 1251|   352k|            sd->table[1][i] = i;
 1252|   352k|        }
 1253|       |
 1254|  1.17M|        for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   49|  1.17M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1254:16): [True: 1.17M, False: 372]
  ------------------
 1255|  1.17M|            sd->table[0][i] = sd->table[1][0] = 0;
 1256|  1.17M|        }
 1257|       |
 1258|    372|        sd->sp = sd->stack;
 1259|       |
 1260|    372|        return 0;
 1261|       |
 1262|   282k|    } else if (sd->fresh) {
  ------------------
  |  Branch (1262:16): [True: 372, False: 282k]
  ------------------
 1263|    372|        sd->fresh = FALSE;
  ------------------
  |  |   43|    372|#define FALSE 0
  ------------------
 1264|       |
 1265|    915|        do {
 1266|    915|            sd->firstcode = sd->oldcode =
 1267|    915|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   43|    915|#define FALSE 0
  ------------------
 1268|    915|        } while (sd->firstcode == sd->clear_code);
  ------------------
  |  Branch (1268:18): [True: 543, False: 372]
  ------------------
 1269|       |
 1270|    372|        return sd->firstcode;
 1271|    372|    }
 1272|       |
 1273|   282k|    if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1273:9): [True: 158k, False: 123k]
  ------------------
 1274|   158k|        return *--sd->sp;
 1275|   158k|    }
 1276|       |
 1277|   123k|    while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   43|   123k|#define FALSE 0
  ------------------
  |  Branch (1277:12): [True: 122k, False: 573]
  ------------------
 1278|   122k|        if (code == sd->clear_code) {
  ------------------
  |  Branch (1278:13): [True: 1.90k, False: 120k]
  ------------------
 1279|  1.05M|            for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1279:25): [True: 1.05M, False: 1.90k]
  ------------------
 1280|  1.05M|                sd->table[0][i] = 0;
 1281|  1.05M|                sd->table[1][i] = i;
 1282|  1.05M|            }
 1283|       |
 1284|  6.75M|            for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   49|  6.75M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1284:20): [True: 6.75M, False: 1.90k]
  ------------------
 1285|  6.75M|                sd->table[0][i] = sd->table[1][i] = 0;
 1286|  6.75M|            }
 1287|       |
 1288|  1.90k|            sd->code_size = sd->set_code_size + 1;
 1289|  1.90k|            sd->max_code_size = 2 * sd->clear_code;
 1290|  1.90k|            sd->max_code = sd->clear_code + 2;
 1291|  1.90k|            sd->sp = sd->stack;
 1292|  1.90k|            sd->firstcode = sd->oldcode =
 1293|  1.90k|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   43|  1.90k|#define FALSE 0
  ------------------
 1294|       |
 1295|  1.90k|            return sd->firstcode;
 1296|   120k|        } else if (code == sd->end_code) {
  ------------------
  |  Branch (1296:20): [True: 247, False: 120k]
  ------------------
 1297|    247|            int count;
 1298|    247|            unsigned char buf[260];
 1299|       |
 1300|    247|            if (*ZeroDataBlockP) {
  ------------------
  |  Branch (1300:17): [True: 3, False: 244]
  ------------------
 1301|      3|                return -2;
 1302|      3|            }
 1303|       |
 1304|    553|            while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
  ------------------
  |  Branch (1304:20): [True: 309, False: 244]
  ------------------
 1305|    309|                ;
 1306|       |
 1307|    244|            if (count != 0) {
  ------------------
  |  Branch (1307:17): [True: 33, False: 211]
  ------------------
 1308|     33|                return -2;
 1309|     33|            }
 1310|    244|        }
 1311|       |
 1312|   120k|        incode = code;
 1313|       |
 1314|   120k|        if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   82|   120k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   49|   120k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1314:13): [True: 0, False: 120k]
  ------------------
 1315|       |            /* Bad compressed data stream */
 1316|      0|            return -1;
 1317|      0|        }
 1318|       |
 1319|   120k|        if (code >= sd->max_code) {
  ------------------
  |  Branch (1319:13): [True: 30.6k, False: 90.3k]
  ------------------
 1320|  30.6k|            *sd->sp++ = sd->firstcode;
 1321|  30.6k|            code = sd->oldcode;
 1322|  30.6k|        }
 1323|       |
 1324|   273k|        while (code >= sd->clear_code) {
  ------------------
  |  Branch (1324:16): [True: 152k, False: 120k]
  ------------------
 1325|   152k|            if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   82|   152k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   49|   152k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1325:17): [True: 3, False: 152k]
  ------------------
 1326|       |                /* Bad compressed data stream */
 1327|      3|                return -1;
 1328|      3|            }
 1329|   152k|            if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   49|   152k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1329:17): [True: 7, False: 152k]
  ------------------
 1330|       |                /* Corrupted code */
 1331|      7|                return -1;
 1332|      7|            }
 1333|       |
 1334|   152k|            *sd->sp++ = sd->table[1][code];
 1335|       |
 1336|   152k|            if (code == sd->table[0][code]) {
  ------------------
  |  Branch (1336:17): [True: 24.5k, False: 128k]
  ------------------
 1337|       |                /* Oh well */
 1338|  24.5k|            }
 1339|       |
 1340|   152k|            code = sd->table[0][code];
 1341|   152k|        }
 1342|   120k|        if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   49|   120k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1342:13): [True: 0, False: 120k]
  ------------------
 1343|       |            /* Corrupted code */
 1344|      0|            return -1;
 1345|      0|        }
 1346|       |
 1347|   120k|        *sd->sp++ = sd->firstcode = sd->table[1][code];
 1348|       |
 1349|   120k|        if ((code = sd->max_code) < (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   49|   120k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1349:13): [True: 115k, False: 5.49k]
  ------------------
 1350|   115k|            sd->table[0][code] = sd->oldcode;
 1351|   115k|            sd->table[1][code] = sd->firstcode;
 1352|   115k|            ++sd->max_code;
 1353|       |
 1354|   115k|            if ((sd->max_code >= sd->max_code_size) && (sd->max_code_size < (1 << MAX_LWZ_BITS))) {
  ------------------
  |  |   49|  1.51k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1354:17): [True: 1.51k, False: 113k]
  |  Branch (1354:56): [True: 1.47k, False: 40]
  ------------------
 1355|  1.47k|                sd->max_code_size *= 2;
 1356|  1.47k|                ++sd->code_size;
 1357|  1.47k|            }
 1358|   115k|        }
 1359|       |
 1360|   120k|        sd->oldcode = incode;
 1361|       |
 1362|   120k|        if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1362:13): [True: 120k, False: 0]
  ------------------
 1363|   120k|            return *--sd->sp;
 1364|   120k|        }
 1365|   120k|    }
 1366|       |
 1367|    573|    return code;
 1368|   123k|}
gd_gif_in.c:GetCode:
 1220|   126k|{
 1221|   126k|    int rv;
 1222|       |
 1223|   126k|    rv = GetCode_(fd, scd, code_size, flag, ZeroDataBlockP);
 1224|       |
 1225|   126k|    if (VERBOSE) {
  ------------------
  |  |   36|   126k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (36:17): [Folded, False: 126k]
  |  |  ------------------
  ------------------
 1226|      0|        printf("[GetCode(,%d,%d) returning %d]\n", code_size, flag, rv);
 1227|      0|    }
 1228|       |
 1229|   126k|    return rv;
 1230|   126k|}
gd_gif_in.c:GetCode_:
 1160|   126k|{
 1161|   126k|    int i, j, ret;
 1162|   126k|    int count;
 1163|       |
 1164|   126k|    if (flag) {
  ------------------
  |  Branch (1164:9): [True: 372, False: 126k]
  ------------------
 1165|    372|        scd->curbit = 0;
 1166|    372|        scd->lastbit = 0;
 1167|    372|        scd->last_byte = 2;
 1168|    372|        scd->done = FALSE;
  ------------------
  |  |   43|    372|#define FALSE 0
  ------------------
 1169|    372|        return 0;
 1170|    372|    }
 1171|       |
 1172|   126k|    if ((scd->curbit + code_size) >= scd->lastbit) {
  ------------------
  |  Branch (1172:9): [True: 4.07k, False: 122k]
  ------------------
 1173|  4.07k|        if (scd->done) {
  ------------------
  |  Branch (1173:13): [True: 419, False: 3.65k]
  ------------------
 1174|    419|            if (scd->curbit >= scd->lastbit) {
  ------------------
  |  Branch (1174:17): [True: 241, False: 178]
  ------------------
 1175|       |                /* Oh well */
 1176|    241|            }
 1177|    419|            return -1;
 1178|    419|        }
 1179|       |
 1180|  3.65k|        scd->buf[0] = scd->buf[scd->last_byte - 2];
 1181|  3.65k|        scd->buf[1] = scd->buf[scd->last_byte - 1];
 1182|  3.65k|        scd->last_byte = 2;
 1183|  3.65k|        scd->curbit = (scd->curbit - scd->lastbit) + 16;
 1184|  3.65k|        scd->lastbit = 16;
 1185|       |
 1186|  4.35k|        do {
 1187|  4.35k|            if (scd->last_byte > (CSD_BUF_SIZE - 255)) {
  ------------------
  |  |   84|  4.35k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1187:17): [True: 0, False: 4.35k]
  ------------------
 1188|      0|                return -1;
 1189|      0|            }
 1190|       |
 1191|  4.35k|            if ((count = GetDataBlock(fd, &scd->buf[scd->last_byte], ZeroDataBlockP)) <= 0) {
  ------------------
  |  Branch (1191:17): [True: 339, False: 4.01k]
  ------------------
 1192|    339|                scd->done = TRUE;
  ------------------
  |  |   42|    339|#define TRUE 1
  ------------------
 1193|    339|                break;
 1194|    339|            }
 1195|       |
 1196|  4.01k|            scd->last_byte += count;
 1197|  4.01k|            scd->lastbit += count * 8;
 1198|  4.01k|        } while ((scd->curbit + code_size) > scd->lastbit);
  ------------------
  |  Branch (1198:18): [True: 698, False: 3.31k]
  ------------------
 1199|  3.65k|    }
 1200|       |
 1201|   125k|    if ((scd->curbit + code_size) > scd->lastbit) {
  ------------------
  |  Branch (1201:9): [True: 234, False: 125k]
  ------------------
 1202|    234|        return -1;
 1203|    234|    }
 1204|       |
 1205|   125k|    if ((scd->curbit + code_size - 1) >= (CSD_BUF_SIZE * 8)) {
  ------------------
  |  |   84|   125k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1205:9): [True: 0, False: 125k]
  ------------------
 1206|      0|        ret = -1;
 1207|   125k|    } else {
 1208|   125k|        ret = 0;
 1209|  1.53M|        for (i = scd->curbit, j = 0; j < code_size; ++i, ++j) {
  ------------------
  |  Branch (1209:38): [True: 1.41M, False: 125k]
  ------------------
 1210|  1.41M|            ret |= ((scd->buf[i / 8] & (1 << (i % 8))) != 0) << j;
 1211|  1.41M|        }
 1212|   125k|    }
 1213|       |
 1214|   125k|    scd->curbit += code_size;
 1215|       |
 1216|   125k|    return ret;
 1217|   125k|}

gdGetBuf:
  189|  5.17M|int gdGetBuf(void *buf, int size, gdIOCtx *ctx) { return (ctx->getBuf)(ctx, buf, size); }

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

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

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

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

