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

gdImageCreateFromGifPtr:
  968|    782|{
  969|    782|    gdImagePtr im;
  970|    782|    gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
  971|    782|    if (!in) {
  ------------------
  |  Branch (971:9): [True: 0, False: 782]
  ------------------
  972|      0|        return 0;
  973|      0|    }
  974|    782|    im = gdImageCreateFromGifCtx(in);
  975|    782|    in->gd_free(in);
  976|    782|    return im;
  977|    782|}
gdImageCreateFromGifCtx:
  980|    782|{
  981|    782|    int BitPixel;
  982|       |#if 0
  983|       |	int ColorResolution;
  984|       |	int Background;
  985|       |	int AspectRatio;
  986|       |#endif
  987|    782|    int Transparent = (-1);
  988|    782|    unsigned char buf[16];
  989|    782|    unsigned char c;
  990|    782|    unsigned char ColorMap[3][MAXCOLORMAPSIZE];
  991|    782|    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
  992|    782|    int imw, imh, screen_width, screen_height;
  993|    782|    int useGlobalColormap;
  994|    782|    int bitPixel, i;
  995|       |    /*1.4//int             imageCount = 0; */
  996|       |    /* 2.0.28: threadsafe storage */
  997|    782|    int ZeroDataBlock = FALSE;
  ------------------
  |  |   44|    782|#define FALSE 0
  ------------------
  998|    782|    int haveGlobalColormap;
  999|       |
 1000|    782|    gdImagePtr im = 0;
 1001|       |
 1002|    782|    memset(ColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    782|#define MAXCOLORMAPSIZE 256
  ------------------
 1003|    782|    memset(localColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    782|#define MAXCOLORMAPSIZE 256
  ------------------
 1004|       |
 1005|    782|    if (!ReadOK(fd, buf, 6)) {
  ------------------
  |  |   57|    782|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1005:9): [True: 4, False: 778]
  ------------------
 1006|      4|        return 0;
 1007|      4|    }
 1008|       |
 1009|    778|    if (strncmp((char *)buf, "GIF", 3) != 0) {
  ------------------
  |  Branch (1009:9): [True: 34, False: 744]
  ------------------
 1010|     34|        return 0;
 1011|     34|    }
 1012|       |
 1013|    744|    if (memcmp((char *)buf + 3, "87a", 3) == 0) {
  ------------------
  |  Branch (1013:9): [True: 255, False: 489]
  ------------------
 1014|       |        /* GIF87a */
 1015|    489|    } else if (memcmp((char *)buf + 3, "89a", 3) == 0) {
  ------------------
  |  Branch (1015:16): [True: 457, False: 32]
  ------------------
 1016|       |        /* GIF89a */
 1017|    457|    } else {
 1018|     32|        return 0;
 1019|     32|    }
 1020|       |
 1021|    712|    if (!ReadOK(fd, buf, 7)) {
  ------------------
  |  |   57|    712|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1021:9): [True: 6, False: 706]
  ------------------
 1022|      6|        return 0;
 1023|      6|    }
 1024|       |
 1025|    706|    BitPixel = 2 << (buf[4] & 0x07);
 1026|       |#if 0
 1027|       |	ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
 1028|       |	Background = buf[5];
 1029|       |	AspectRatio = buf[6];
 1030|       |#endif
 1031|    706|    screen_width = imw = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    706|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1032|    706|    screen_height = imh = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    706|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1033|       |
 1034|    706|    haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
  ------------------
  |  |   55|    706|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1035|    706|    if (haveGlobalColormap) {
  ------------------
  |  Branch (1035:9): [True: 23, False: 683]
  ------------------
 1036|     23|        if (ReadColorMap(fd, BitPixel, ColorMap)) {
  ------------------
  |  Branch (1036:13): [True: 20, False: 3]
  ------------------
 1037|     20|            return 0;
 1038|     20|        }
 1039|     23|    }
 1040|       |
 1041|  4.60M|    for (;;) {
 1042|  4.60M|        int top, left;
 1043|  4.60M|        int width, height;
 1044|       |
 1045|  4.60M|        if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  4.60M|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1045:13): [True: 197, False: 4.59M]
  ------------------
 1046|    197|            return 0;
 1047|    197|        }
 1048|       |
 1049|  4.59M|        if (c == ';') { /* GIF terminator */
  ------------------
  |  Branch (1049:13): [True: 1, False: 4.59M]
  ------------------
 1050|      1|            goto terminated;
 1051|      1|        }
 1052|       |
 1053|  4.59M|        if (c == '!') { /* Extension */
  ------------------
  |  Branch (1053:13): [True: 19.6k, False: 4.58M]
  ------------------
 1054|  19.6k|            if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  19.6k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1054:17): [True: 1, False: 19.6k]
  ------------------
 1055|      1|                return 0;
 1056|      1|            }
 1057|       |
 1058|  19.6k|            DoExtension(fd, c, &Transparent, &ZeroDataBlock);
 1059|  19.6k|            continue;
 1060|  19.6k|        }
 1061|       |
 1062|  4.58M|        if (c != ',') { /* Not a valid start character */
  ------------------
  |  Branch (1062:13): [True: 4.57M, False: 487]
  ------------------
 1063|  4.57M|            continue;
 1064|  4.57M|        }
 1065|       |
 1066|       |        /*1.4//++imageCount; */
 1067|       |
 1068|    487|        if (!ReadOK(fd, buf, 9)) {
  ------------------
  |  |   57|    487|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1068:13): [True: 5, False: 482]
  ------------------
 1069|      5|            return 0;
 1070|      5|        }
 1071|       |
 1072|    482|        useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
  ------------------
  |  |   55|    482|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1073|       |
 1074|    482|        bitPixel = 1 << ((buf[8] & 0x07) + 1);
 1075|    482|        left = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1076|    482|        top = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1077|    482|        width = LM_to_uint(buf[4], buf[5]);
  ------------------
  |  |   59|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1078|    482|        height = LM_to_uint(buf[6], buf[7]);
  ------------------
  |  |   59|    482|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1079|       |
 1080|    482|        if (((left + width) > screen_width) || ((top + height) > screen_height)) {
  ------------------
  |  Branch (1080:13): [True: 21, False: 461]
  |  Branch (1080:48): [True: 20, False: 441]
  ------------------
 1081|     41|            if (VERBOSE) {
  ------------------
  |  |   37|     41|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 41]
  |  |  ------------------
  ------------------
 1082|      0|                printf("Frame is not confined to screen dimension.\n");
 1083|      0|            }
 1084|     41|            return 0;
 1085|     41|        }
 1086|       |
 1087|    441|        if (!(im = gdImageCreate(width, height))) {
  ------------------
  |  Branch (1087:13): [True: 37, False: 404]
  ------------------
 1088|     37|            return 0;
 1089|     37|        }
 1090|       |
 1091|    404|        im->interlace = BitSet(buf[8], INTERLACE);
  ------------------
  |  |   55|    404|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1092|    404|        if (!useGlobalColormap) {
  ------------------
  |  Branch (1092:13): [True: 25, False: 379]
  ------------------
 1093|     25|            if (ReadColorMap(fd, bitPixel, localColorMap)) {
  ------------------
  |  Branch (1093:17): [True: 17, False: 8]
  ------------------
 1094|     17|                gdImageDestroy(im);
 1095|     17|                return 0;
 1096|     17|            }
 1097|       |
 1098|       |            /* Legacy gdImageCreateFromGif* is intentionally tolerant of
 1099|       |             * out-of-palette LZW results and maps them to color 0. The newer
 1100|       |             * iterator API passes the actual color table size and rejects those
 1101|       |             * malformed frames instead.
 1102|       |             */
 1103|      8|            if (!ReadImage(im, fd, width, height, localColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|      8|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1103:17): [True: 2, False: 6]
  ------------------
 1104|      8|                           &ZeroDataBlock)) {
 1105|      2|                gdImageDestroy(im);
 1106|      2|                return 0;
 1107|      2|            }
 1108|    379|        } else {
 1109|    379|            if (!haveGlobalColormap) {
  ------------------
  |  Branch (1109:17): [True: 378, False: 1]
  ------------------
 1110|       |                // Still a valid gif, apply simple default palette as per spec
 1111|    378|                ColorMap[CM_RED][1] = 0xff;
  ------------------
  |  |   46|    378|#define CM_RED 0
  ------------------
 1112|    378|                ColorMap[CM_GREEN][1] = 0xff;
  ------------------
  |  |   47|    378|#define CM_GREEN 1
  ------------------
 1113|    378|                ColorMap[CM_BLUE][1] = 0xff;
  ------------------
  |  |   48|    378|#define CM_BLUE 2
  ------------------
 1114|    378|            }
 1115|       |
 1116|       |            /* Keep legacy tolerance here as above; strict validation is used by
 1117|       |             * the animated GIF iterator.
 1118|       |             */
 1119|    379|            if (!ReadImage(im, fd, width, height, ColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|    379|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1119:17): [True: 21, False: 358]
  ------------------
 1120|    379|                           &ZeroDataBlock)) {
 1121|     21|                gdImageDestroy(im);
 1122|     21|                return 0;
 1123|     21|            }
 1124|    379|        }
 1125|       |
 1126|    364|        if (Transparent != (-1)) {
  ------------------
  |  Branch (1126:13): [True: 15, False: 349]
  ------------------
 1127|     15|            gdImageColorTransparent(im, Transparent);
 1128|     15|        }
 1129|       |
 1130|    364|        goto terminated;
 1131|    404|    }
 1132|       |
 1133|    365|terminated:
 1134|       |    /* Terminator before any image was declared! */
 1135|    365|    if (!im) {
  ------------------
  |  Branch (1135:9): [True: 1, False: 364]
  ------------------
 1136|      1|        return 0;
 1137|      1|    }
 1138|       |
 1139|       |    /* Check for open colors at the end, so
 1140|       |     * we can reduce colorsTotal and ultimately
 1141|       |     * BitsPerPixel */
 1142|  76.1k|    for (i = im->colorsTotal - 1; i >= 0; i--) {
  ------------------
  |  Branch (1142:35): [True: 76.0k, False: 43]
  ------------------
 1143|  76.0k|        if (im->open[i]) {
  ------------------
  |  Branch (1143:13): [True: 75.7k, False: 321]
  ------------------
 1144|  75.7k|            im->colorsTotal--;
 1145|  75.7k|        } else {
 1146|    321|            break;
 1147|    321|        }
 1148|  76.0k|    }
 1149|       |
 1150|    364|    if (!im->colorsTotal) {
  ------------------
  |  Branch (1150:9): [True: 43, False: 321]
  ------------------
 1151|     43|        gdImageDestroy(im);
 1152|     43|        return 0;
 1153|     43|    }
 1154|       |
 1155|    321|    return im;
 1156|    364|}
gd_gif_in.c:GetDataBlock:
 1226|   152k|{
 1227|   152k|    int rv, i;
 1228|       |
 1229|   152k|    rv = GetDataBlock_(fd, buf, ZeroDataBlockP);
 1230|       |
 1231|   152k|    if (VERBOSE) {
  ------------------
  |  |   37|   152k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 152k]
  |  |  ------------------
  ------------------
 1232|      0|        printf("[GetDataBlock returning %d", rv);
 1233|      0|        if (rv > 0) {
  ------------------
  |  Branch (1233:13): [True: 0, False: 0]
  ------------------
 1234|      0|            printf(":");
 1235|      0|            for (i = 0; i < rv; i++) {
  ------------------
  |  Branch (1235:25): [True: 0, False: 0]
  ------------------
 1236|      0|                printf(" %02x", buf[i]);
 1237|      0|            }
 1238|      0|        }
 1239|      0|        printf("]\n");
 1240|      0|    }
 1241|       |
 1242|   152k|    return rv;
 1243|   152k|}
gd_gif_in.c:GetDataBlock_:
 1209|   152k|{
 1210|   152k|    unsigned char count;
 1211|       |
 1212|   152k|    if (!ReadOK(fd, &count, 1)) {
  ------------------
  |  |   57|   152k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1212:9): [True: 449, False: 151k]
  ------------------
 1213|    449|        return -1;
 1214|    449|    }
 1215|       |
 1216|   151k|    *ZeroDataBlockP = count == 0;
 1217|       |
 1218|   151k|    if ((count != 0) && (!ReadOK(fd, buf, count))) {
  ------------------
  |  |   57|   129k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1218:9): [True: 129k, False: 21.8k]
  |  Branch (1218:25): [True: 85, False: 129k]
  ------------------
 1219|     85|        return -1;
 1220|     85|    }
 1221|       |
 1222|   151k|    return count;
 1223|   151k|}
gd_gif_in.c:ReadColorMap:
 1159|     48|{
 1160|     48|    int i;
 1161|     48|    unsigned char rgb[3];
 1162|       |
 1163|  1.47k|    for (i = 0; i < number; ++i) {
  ------------------
  |  Branch (1163:17): [True: 1.46k, False: 11]
  ------------------
 1164|  1.46k|        if (!ReadOK(fd, rgb, sizeof(rgb))) {
  ------------------
  |  |   57|  1.46k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1164:13): [True: 37, False: 1.43k]
  ------------------
 1165|     37|            return TRUE;
  ------------------
  |  |   43|     37|#define TRUE 1
  ------------------
 1166|     37|        }
 1167|       |
 1168|  1.43k|        buffer[CM_RED][i] = rgb[0];
  ------------------
  |  |   46|  1.43k|#define CM_RED 0
  ------------------
 1169|  1.43k|        buffer[CM_GREEN][i] = rgb[1];
  ------------------
  |  |   47|  1.43k|#define CM_GREEN 1
  ------------------
 1170|  1.43k|        buffer[CM_BLUE][i] = rgb[2];
  ------------------
  |  |   48|  1.43k|#define CM_BLUE 2
  ------------------
 1171|  1.43k|    }
 1172|       |
 1173|     11|    return FALSE;
  ------------------
  |  |   44|     11|#define FALSE 0
  ------------------
 1174|     48|}
gd_gif_in.c:DoExtension:
 1177|  19.6k|{
 1178|  19.6k|    unsigned char buf[256];
 1179|       |
 1180|  19.6k|    switch (label) {
 1181|  16.0k|    case 0xf9:             /* Graphic Control Extension */
  ------------------
  |  Branch (1181:5): [True: 16.0k, False: 3.64k]
  ------------------
 1182|  16.0k|        memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
 1183|  16.0k|        (void)GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP);
 1184|       |#if 0
 1185|       |		Gif89.disposal  = (buf[0] >> 2) & 0x7;
 1186|       |		Gif89.inputFlag = (buf[0] >> 1) & 0x1;
 1187|       |		Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
 1188|       |#endif
 1189|  16.0k|        if ((buf[0] & 0x1) != 0) {
  ------------------
  |  Branch (1189:13): [True: 10.6k, False: 5.36k]
  ------------------
 1190|  10.6k|            *Transparent = buf[3];
 1191|  10.6k|        }
 1192|       |
 1193|  50.7k|        while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1193:16): [True: 34.7k, False: 16.0k]
  ------------------
 1194|  34.7k|            ;
 1195|       |
 1196|  16.0k|        return FALSE;
  ------------------
  |  |   44|  16.0k|#define FALSE 0
  ------------------
 1197|       |
 1198|  3.64k|    default:
  ------------------
  |  Branch (1198:5): [True: 3.64k, False: 16.0k]
  ------------------
 1199|  3.64k|        break;
 1200|  19.6k|    }
 1201|       |
 1202|  81.0k|    while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1202:12): [True: 77.3k, False: 3.64k]
  ------------------
 1203|  77.3k|        ;
 1204|       |
 1205|  3.64k|    return FALSE;
  ------------------
  |  |   44|  3.64k|#define FALSE 0
  ------------------
 1206|  19.6k|}
gd_gif_in.c:ReadImage:
 1473|    387|{
 1474|    387|    unsigned char c;
 1475|    387|    int xpos = 0, ypos = 0, pass = 0;
 1476|    387|    int v, i;
 1477|    387|    LZW_STATIC_DATA sd;
 1478|       |
 1479|       |    /* Initialize the Compression routines */
 1480|    387|    if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|    387|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1480:9): [True: 17, False: 370]
  ------------------
 1481|     17|        return 0;
 1482|     17|    }
 1483|       |
 1484|    370|    if (c > MAX_LWZ_BITS) {
  ------------------
  |  |   50|    370|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1484:9): [True: 6, False: 364]
  ------------------
 1485|      6|        return 0;
 1486|      6|    }
 1487|       |
 1488|       |    /* Stash the color map into the image */
 1489|  93.5k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  93.5k|#define gdMaxColors 256
  ------------------
  |  Branch (1489:17): [True: 93.1k, False: 364]
  ------------------
 1490|  93.1k|        im->red[i] = cmap[CM_RED][i];
  ------------------
  |  |   46|  93.1k|#define CM_RED 0
  ------------------
 1491|  93.1k|        im->green[i] = cmap[CM_GREEN][i];
  ------------------
  |  |   47|  93.1k|#define CM_GREEN 1
  ------------------
 1492|  93.1k|        im->blue[i] = cmap[CM_BLUE][i];
  ------------------
  |  |   48|  93.1k|#define CM_BLUE 2
  ------------------
 1493|  93.1k|        im->open[i] = 1;
 1494|  93.1k|    }
 1495|       |
 1496|       |    /* Many (perhaps most) of these colors will remain marked open. */
 1497|    364|    im->colorsTotal = gdMaxColors;
  ------------------
  |  |  117|    364|#define gdMaxColors 256
  ------------------
 1498|    364|    if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
  ------------------
  |  |   43|    364|#define TRUE 1
  ------------------
  |  Branch (1498:9): [True: 0, False: 364]
  ------------------
 1499|      0|        return 0;
 1500|      0|    }
 1501|       |
 1502|       |    /*
 1503|       |    **  If this is an "uninteresting picture" ignore it.
 1504|       |    **  REMOVED For 1.4
 1505|       |    */
 1506|       |    /*if (ignore) { */
 1507|       |    /*        while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */
 1508|       |    /*                ; */
 1509|       |    /*        return; */
 1510|       |    /*} */
 1511|       |
 1512|   269k|    while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   269k|#define FALSE 0
  ------------------
  |  Branch (1512:12): [True: 268k, False: 351]
  ------------------
 1513|   268k|        if (colorCount > 0 && v >= colorCount) {
  ------------------
  |  Branch (1513:13): [True: 0, False: 268k]
  |  Branch (1513:31): [True: 0, False: 0]
  ------------------
 1514|      0|            return 0;
 1515|      0|        }
 1516|   268k|        if (v >= gdMaxColors) {
  ------------------
  |  |  117|   268k|#define gdMaxColors 256
  ------------------
  |  Branch (1516:13): [True: 79.9k, False: 188k]
  ------------------
 1517|  79.9k|            v = 0;
 1518|  79.9k|        }
 1519|       |
 1520|       |        /* This how we recognize which colors are actually used. */
 1521|   268k|        if (im->open[v]) {
  ------------------
  |  Branch (1521:13): [True: 2.24k, False: 266k]
  ------------------
 1522|  2.24k|            im->open[v] = 0;
 1523|  2.24k|        }
 1524|       |
 1525|   268k|        gdImageSetPixel(im, xpos, ypos, v);
 1526|       |
 1527|   268k|        ++xpos;
 1528|   268k|        if (xpos == len) {
  ------------------
  |  Branch (1528:13): [True: 28.8k, False: 240k]
  ------------------
 1529|  28.8k|            xpos = 0;
 1530|  28.8k|            if (interlace) {
  ------------------
  |  Branch (1530:17): [True: 25.8k, False: 2.93k]
  ------------------
 1531|  25.8k|                switch (pass) {
  ------------------
  |  Branch (1531:25): [True: 25.8k, False: 0]
  ------------------
 1532|  9.67k|                case 0:
  ------------------
  |  Branch (1532:17): [True: 9.67k, False: 16.2k]
  ------------------
 1533|  14.2k|                case 1:
  ------------------
  |  Branch (1533:17): [True: 4.54k, False: 21.3k]
  ------------------
 1534|  14.2k|                    ypos += 8;
 1535|  14.2k|                    break;
 1536|  6.02k|                case 2:
  ------------------
  |  Branch (1536:17): [True: 6.02k, False: 19.8k]
  ------------------
 1537|  6.02k|                    ypos += 4;
 1538|  6.02k|                    break;
 1539|  5.65k|                case 3:
  ------------------
  |  Branch (1539:17): [True: 5.65k, False: 20.2k]
  ------------------
 1540|  5.65k|                    ypos += 2;
 1541|  5.65k|                    break;
 1542|  25.8k|                }
 1543|       |
 1544|  25.8k|                if (ypos >= height) {
  ------------------
  |  Branch (1544:21): [True: 118, False: 25.7k]
  ------------------
 1545|    118|                    ++pass;
 1546|    118|                    switch (pass) {
 1547|     50|                    case 1:
  ------------------
  |  Branch (1547:21): [True: 50, False: 68]
  ------------------
 1548|     50|                        ypos = 4;
 1549|     50|                        break;
 1550|     41|                    case 2:
  ------------------
  |  Branch (1550:21): [True: 41, False: 77]
  ------------------
 1551|     41|                        ypos = 2;
 1552|     41|                        break;
 1553|     20|                    case 3:
  ------------------
  |  Branch (1553:21): [True: 20, False: 98]
  ------------------
 1554|     20|                        ypos = 1;
 1555|     20|                        break;
 1556|      7|                    default:
  ------------------
  |  Branch (1556:21): [True: 7, False: 111]
  ------------------
 1557|      7|                        goto fini;
 1558|    118|                    }
 1559|    118|                }
 1560|  25.8k|            } else {
 1561|  2.93k|                ++ypos;
 1562|  2.93k|            }
 1563|  28.8k|        }
 1564|       |
 1565|   268k|        if (ypos >= height) {
  ------------------
  |  Branch (1565:13): [True: 6, False: 268k]
  ------------------
 1566|      6|            break;
 1567|      6|        }
 1568|   268k|    }
 1569|       |
 1570|    364|fini:
 1571|    364|    if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >= 0) {
  ------------------
  |  |   44|    364|#define FALSE 0
  ------------------
  |  Branch (1571:9): [True: 29, False: 335]
  ------------------
 1572|       |        /* Ignore extra */
 1573|     29|    }
 1574|    364|    return 1;
 1575|    364|}
gd_gif_in.c:LWZReadByte:
 1459|   270k|{
 1460|   270k|    int rv;
 1461|       |
 1462|   270k|    rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
 1463|       |
 1464|   270k|    if (VERBOSE) {
  ------------------
  |  |   37|   270k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 270k]
  |  |  ------------------
  ------------------
 1465|      0|        printf("[LWZReadByte(,%d,%d) returning %d]\n", flag, input_code_size, rv);
 1466|      0|    }
 1467|       |
 1468|   270k|    return rv;
 1469|   270k|}
gd_gif_in.c:LWZReadByte_:
 1321|   270k|{
 1322|   270k|    int code, incode, i;
 1323|       |
 1324|   270k|    if (flag) {
  ------------------
  |  Branch (1324:9): [True: 364, False: 269k]
  ------------------
 1325|    364|        sd->set_code_size = input_code_size;
 1326|    364|        sd->code_size = sd->set_code_size + 1;
 1327|    364|        sd->clear_code = 1 << sd->set_code_size;
 1328|    364|        sd->end_code = sd->clear_code + 1;
 1329|    364|        sd->max_code_size = 2 * sd->clear_code;
 1330|    364|        sd->max_code = sd->clear_code + 2;
 1331|       |
 1332|    364|        GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
  ------------------
  |  |   43|    364|#define TRUE 1
  ------------------
 1333|       |
 1334|    364|        sd->fresh = TRUE;
  ------------------
  |  |   43|    364|#define TRUE 1
  ------------------
 1335|       |
 1336|   309k|        for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1336:21): [True: 309k, False: 364]
  ------------------
 1337|   309k|            sd->table[0][i] = 0;
 1338|   309k|            sd->table[1][i] = i;
 1339|   309k|        }
 1340|       |
 1341|  1.18M|        for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  1.18M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1341:16): [True: 1.18M, False: 364]
  ------------------
 1342|  1.18M|            sd->table[0][i] = sd->table[1][0] = 0;
 1343|  1.18M|        }
 1344|       |
 1345|    364|        sd->sp = sd->stack;
 1346|       |
 1347|    364|        return 0;
 1348|       |
 1349|   269k|    } else if (sd->fresh) {
  ------------------
  |  Branch (1349:16): [True: 364, False: 269k]
  ------------------
 1350|    364|        sd->fresh = FALSE;
  ------------------
  |  |   44|    364|#define FALSE 0
  ------------------
 1351|       |
 1352|  1.04k|        do {
 1353|  1.04k|            sd->firstcode = sd->oldcode =
 1354|  1.04k|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|  1.04k|#define FALSE 0
  ------------------
 1355|  1.04k|        } while (sd->firstcode == sd->clear_code);
  ------------------
  |  Branch (1355:18): [True: 679, False: 364]
  ------------------
 1356|       |
 1357|    364|        return sd->firstcode;
 1358|    364|    }
 1359|       |
 1360|   269k|    if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1360:9): [True: 158k, False: 111k]
  ------------------
 1361|   158k|        return *--sd->sp;
 1362|   158k|    }
 1363|       |
 1364|   111k|    while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   111k|#define FALSE 0
  ------------------
  |  Branch (1364:12): [True: 110k, False: 561]
  ------------------
 1365|   110k|        if (code == sd->clear_code) {
  ------------------
  |  Branch (1365:13): [True: 2.08k, False: 108k]
  ------------------
 1366|   873k|            for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1366:25): [True: 871k, False: 2.08k]
  ------------------
 1367|   871k|                sd->table[0][i] = 0;
 1368|   871k|                sd->table[1][i] = i;
 1369|   871k|            }
 1370|       |
 1371|  7.67M|            for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  7.67M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1371:20): [True: 7.67M, False: 2.08k]
  ------------------
 1372|  7.67M|                sd->table[0][i] = sd->table[1][i] = 0;
 1373|  7.67M|            }
 1374|       |
 1375|  2.08k|            sd->code_size = sd->set_code_size + 1;
 1376|  2.08k|            sd->max_code_size = 2 * sd->clear_code;
 1377|  2.08k|            sd->max_code = sd->clear_code + 2;
 1378|  2.08k|            sd->sp = sd->stack;
 1379|  2.08k|            sd->firstcode = sd->oldcode =
 1380|  2.08k|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|  2.08k|#define FALSE 0
  ------------------
 1381|       |
 1382|  2.08k|            return sd->firstcode;
 1383|   108k|        } else if (code == sd->end_code) {
  ------------------
  |  Branch (1383:20): [True: 323, False: 108k]
  ------------------
 1384|    323|            int count;
 1385|    323|            unsigned char buf[260];
 1386|       |
 1387|    323|            if (*ZeroDataBlockP) {
  ------------------
  |  Branch (1387:17): [True: 5, False: 318]
  ------------------
 1388|      5|                return -2;
 1389|      5|            }
 1390|       |
 1391|    996|            while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
  ------------------
  |  Branch (1391:20): [True: 678, False: 318]
  ------------------
 1392|    678|                ;
 1393|       |
 1394|    318|            if (count != 0) {
  ------------------
  |  Branch (1394:17): [True: 39, False: 279]
  ------------------
 1395|     39|                return -2;
 1396|     39|            }
 1397|    318|        }
 1398|       |
 1399|   108k|        incode = code;
 1400|       |
 1401|   108k|        if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   108k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   108k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1401:13): [True: 0, False: 108k]
  ------------------
 1402|       |            /* Bad compressed data stream */
 1403|      0|            return -1;
 1404|      0|        }
 1405|       |
 1406|   108k|        if (code >= sd->max_code) {
  ------------------
  |  Branch (1406:13): [True: 31.0k, False: 77.4k]
  ------------------
 1407|  31.0k|            *sd->sp++ = sd->firstcode;
 1408|  31.0k|            code = sd->oldcode;
 1409|  31.0k|        }
 1410|       |
 1411|   243k|        while (code >= sd->clear_code) {
  ------------------
  |  Branch (1411:16): [True: 135k, False: 108k]
  ------------------
 1412|   135k|            if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   135k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   135k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1412:17): [True: 1, False: 135k]
  ------------------
 1413|       |                /* Bad compressed data stream */
 1414|      1|                return -1;
 1415|      1|            }
 1416|   135k|            if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   135k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1416:17): [True: 5, False: 135k]
  ------------------
 1417|       |                /* Corrupted code */
 1418|      5|                return -1;
 1419|      5|            }
 1420|       |
 1421|   135k|            *sd->sp++ = sd->table[1][code];
 1422|       |
 1423|   135k|            if (code == sd->table[0][code]) {
  ------------------
  |  Branch (1423:17): [True: 8.19k, False: 126k]
  ------------------
 1424|       |                /* Oh well */
 1425|  8.19k|            }
 1426|       |
 1427|   135k|            code = sd->table[0][code];
 1428|   135k|        }
 1429|   108k|        if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   108k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1429:13): [True: 0, False: 108k]
  ------------------
 1430|       |            /* Corrupted code */
 1431|      0|            return -1;
 1432|      0|        }
 1433|       |
 1434|   108k|        *sd->sp++ = sd->firstcode = sd->table[1][code];
 1435|       |
 1436|   108k|        if ((code = sd->max_code) < (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   108k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1436:13): [True: 107k, False: 1.17k]
  ------------------
 1437|   107k|            sd->table[0][code] = sd->oldcode;
 1438|   107k|            sd->table[1][code] = sd->firstcode;
 1439|   107k|            ++sd->max_code;
 1440|       |
 1441|   107k|            if ((sd->max_code >= sd->max_code_size) && (sd->max_code_size < (1 << MAX_LWZ_BITS))) {
  ------------------
  |  |   50|  2.10k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1441:17): [True: 2.10k, False: 105k]
  |  Branch (1441:56): [True: 2.06k, False: 36]
  ------------------
 1442|  2.06k|                sd->max_code_size *= 2;
 1443|  2.06k|                ++sd->code_size;
 1444|  2.06k|            }
 1445|   107k|        }
 1446|       |
 1447|   108k|        sd->oldcode = incode;
 1448|       |
 1449|   108k|        if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1449:13): [True: 108k, False: 0]
  ------------------
 1450|   108k|            return *--sd->sp;
 1451|   108k|        }
 1452|   108k|    }
 1453|       |
 1454|    561|    return code;
 1455|   111k|}
gd_gif_in.c:GetCode:
 1307|   114k|{
 1308|   114k|    int rv;
 1309|       |
 1310|   114k|    rv = GetCode_(fd, scd, code_size, flag, ZeroDataBlockP);
 1311|       |
 1312|   114k|    if (VERBOSE) {
  ------------------
  |  |   37|   114k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 114k]
  |  |  ------------------
  ------------------
 1313|      0|        printf("[GetCode(,%d,%d) returning %d]\n", code_size, flag, rv);
 1314|      0|    }
 1315|       |
 1316|   114k|    return rv;
 1317|   114k|}
gd_gif_in.c:GetCode_:
 1247|   114k|{
 1248|   114k|    int i, j, ret;
 1249|   114k|    int count;
 1250|       |
 1251|   114k|    if (flag) {
  ------------------
  |  Branch (1251:9): [True: 364, False: 114k]
  ------------------
 1252|    364|        scd->curbit = 0;
 1253|    364|        scd->lastbit = 0;
 1254|    364|        scd->last_byte = 2;
 1255|    364|        scd->done = FALSE;
  ------------------
  |  |   44|    364|#define FALSE 0
  ------------------
 1256|    364|        return 0;
 1257|    364|    }
 1258|       |
 1259|   114k|    if ((scd->curbit + code_size) >= scd->lastbit) {
  ------------------
  |  Branch (1259:9): [True: 3.38k, False: 111k]
  ------------------
 1260|  3.38k|        if (scd->done) {
  ------------------
  |  Branch (1260:13): [True: 410, False: 2.97k]
  ------------------
 1261|    410|            if (scd->curbit >= scd->lastbit) {
  ------------------
  |  Branch (1261:17): [True: 239, False: 171]
  ------------------
 1262|       |                /* Oh well */
 1263|    239|            }
 1264|    410|            return -1;
 1265|    410|        }
 1266|       |
 1267|  2.97k|        scd->buf[0] = scd->buf[scd->last_byte - 2];
 1268|  2.97k|        scd->buf[1] = scd->buf[scd->last_byte - 1];
 1269|  2.97k|        scd->last_byte = 2;
 1270|  2.97k|        scd->curbit = (scd->curbit - scd->lastbit) + 16;
 1271|  2.97k|        scd->lastbit = 16;
 1272|       |
 1273|  3.34k|        do {
 1274|  3.34k|            if (scd->last_byte > (CSD_BUF_SIZE - 255)) {
  ------------------
  |  |   85|  3.34k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1274:17): [True: 0, False: 3.34k]
  ------------------
 1275|      0|                return -1;
 1276|      0|            }
 1277|       |
 1278|  3.34k|            if ((count = GetDataBlock(fd, &scd->buf[scd->last_byte], ZeroDataBlockP)) <= 0) {
  ------------------
  |  Branch (1278:17): [True: 331, False: 3.01k]
  ------------------
 1279|    331|                scd->done = TRUE;
  ------------------
  |  |   43|    331|#define TRUE 1
  ------------------
 1280|    331|                break;
 1281|    331|            }
 1282|       |
 1283|  3.01k|            scd->last_byte += count;
 1284|  3.01k|            scd->lastbit += count * 8;
 1285|  3.01k|        } while ((scd->curbit + code_size) > scd->lastbit);
  ------------------
  |  Branch (1285:18): [True: 367, False: 2.64k]
  ------------------
 1286|  2.97k|    }
 1287|       |
 1288|   113k|    if ((scd->curbit + code_size) > scd->lastbit) {
  ------------------
  |  Branch (1288:9): [True: 226, False: 113k]
  ------------------
 1289|    226|        return -1;
 1290|    226|    }
 1291|       |
 1292|   113k|    if ((scd->curbit + code_size - 1) >= (CSD_BUF_SIZE * 8)) {
  ------------------
  |  |   85|   113k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1292:9): [True: 0, False: 113k]
  ------------------
 1293|      0|        ret = -1;
 1294|   113k|    } else {
 1295|   113k|        ret = 0;
 1296|  1.35M|        for (i = scd->curbit, j = 0; j < code_size; ++i, ++j) {
  ------------------
  |  Branch (1296:38): [True: 1.24M, False: 113k]
  ------------------
 1297|  1.24M|            ret |= ((scd->buf[i / 8] & (1 << (i % 8))) != 0) << j;
 1298|  1.24M|        }
 1299|   113k|    }
 1300|       |
 1301|   113k|    scd->curbit += code_size;
 1302|       |
 1303|   113k|    return ret;
 1304|   113k|}

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

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

overflow2:
   23|  1.25k|{
   24|  1.25k|    if (a <= 0 || b <= 0) {
  ------------------
  |  Branch (24:9): [True: 3, False: 1.24k]
  |  Branch (24:19): [True: 2, False: 1.24k]
  ------------------
   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.24k|    if (a > 100000 / b) {
  ------------------
  |  Branch (29:9): [True: 32, False: 1.21k]
  ------------------
   30|     32|        gd_error_ex(GD_WARNING, "product of memory allocation multiplication would exceed "
  ------------------
  |  |   38|     32|#define GD_WARNING LOG_WARNING
  ------------------
   31|     32|                                "100000, failing operation gracefully\n");
   32|     32|        return 1;
   33|     32|    }
   34|  1.21k|    return 0;
   35|  1.24k|}

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

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

