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

gdImageCreateFromGifPtr:
  968|    799|{
  969|    799|    gdImagePtr im;
  970|    799|    gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
  971|    799|    if (!in) {
  ------------------
  |  Branch (971:9): [True: 0, False: 799]
  ------------------
  972|      0|        return 0;
  973|      0|    }
  974|    799|    im = gdImageCreateFromGifCtx(in);
  975|    799|    in->gd_free(in);
  976|    799|    return im;
  977|    799|}
gdImageCreateFromGifCtx:
  980|    799|{
  981|    799|    int BitPixel;
  982|       |#if 0
  983|       |	int ColorResolution;
  984|       |	int Background;
  985|       |	int AspectRatio;
  986|       |#endif
  987|    799|    int Transparent = (-1);
  988|    799|    unsigned char buf[16];
  989|    799|    unsigned char c;
  990|    799|    unsigned char ColorMap[3][MAXCOLORMAPSIZE];
  991|    799|    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
  992|    799|    int imw, imh, screen_width, screen_height;
  993|    799|    int useGlobalColormap;
  994|    799|    int bitPixel, i;
  995|       |    /*1.4//int             imageCount = 0; */
  996|       |    /* 2.0.28: threadsafe storage */
  997|    799|    int ZeroDataBlock = FALSE;
  ------------------
  |  |   44|    799|#define FALSE 0
  ------------------
  998|    799|    int haveGlobalColormap;
  999|       |
 1000|    799|    gdImagePtr im = 0;
 1001|       |
 1002|    799|    memset(ColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    799|#define MAXCOLORMAPSIZE 256
  ------------------
 1003|    799|    memset(localColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    799|#define MAXCOLORMAPSIZE 256
  ------------------
 1004|       |
 1005|    799|    if (!ReadOK(fd, buf, 6)) {
  ------------------
  |  |   57|    799|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1005:9): [True: 4, False: 795]
  ------------------
 1006|      4|        return 0;
 1007|      4|    }
 1008|       |
 1009|    795|    if (strncmp((char *)buf, "GIF", 3) != 0) {
  ------------------
  |  Branch (1009:9): [True: 33, False: 762]
  ------------------
 1010|     33|        return 0;
 1011|     33|    }
 1012|       |
 1013|    762|    if (memcmp((char *)buf + 3, "87a", 3) == 0) {
  ------------------
  |  Branch (1013:9): [True: 239, False: 523]
  ------------------
 1014|       |        /* GIF87a */
 1015|    523|    } else if (memcmp((char *)buf + 3, "89a", 3) == 0) {
  ------------------
  |  Branch (1015:16): [True: 459, False: 64]
  ------------------
 1016|       |        /* GIF89a */
 1017|    459|    } else {
 1018|     64|        return 0;
 1019|     64|    }
 1020|       |
 1021|    698|    if (!ReadOK(fd, buf, 7)) {
  ------------------
  |  |   57|    698|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1021:9): [True: 6, False: 692]
  ------------------
 1022|      6|        return 0;
 1023|      6|    }
 1024|       |
 1025|    692|    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|    692|    screen_width = imw = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    692|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1032|    692|    screen_height = imh = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    692|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1033|       |
 1034|    692|    haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
  ------------------
  |  |   55|    692|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1035|    692|    if (haveGlobalColormap) {
  ------------------
  |  Branch (1035:9): [True: 23, False: 669]
  ------------------
 1036|     23|        if (ReadColorMap(fd, BitPixel, ColorMap)) {
  ------------------
  |  Branch (1036:13): [True: 19, False: 4]
  ------------------
 1037|     19|            return 0;
 1038|     19|        }
 1039|     23|    }
 1040|       |
 1041|  4.71M|    for (;;) {
 1042|  4.71M|        int top, left;
 1043|  4.71M|        int width, height;
 1044|       |
 1045|  4.71M|        if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  4.71M|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1045:13): [True: 199, False: 4.71M]
  ------------------
 1046|    199|            return 0;
 1047|    199|        }
 1048|       |
 1049|  4.71M|        if (c == ';') { /* GIF terminator */
  ------------------
  |  Branch (1049:13): [True: 2, False: 4.71M]
  ------------------
 1050|      2|            goto terminated;
 1051|      2|        }
 1052|       |
 1053|  4.71M|        if (c == '!') { /* Extension */
  ------------------
  |  Branch (1053:13): [True: 21.4k, False: 4.69M]
  ------------------
 1054|  21.4k|            if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  21.4k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1054:17): [True: 1, False: 21.4k]
  ------------------
 1055|      1|                return 0;
 1056|      1|            }
 1057|       |
 1058|  21.4k|            DoExtension(fd, c, &Transparent, &ZeroDataBlock);
 1059|  21.4k|            continue;
 1060|  21.4k|        }
 1061|       |
 1062|  4.69M|        if (c != ',') { /* Not a valid start character */
  ------------------
  |  Branch (1062:13): [True: 4.69M, False: 471]
  ------------------
 1063|  4.69M|            continue;
 1064|  4.69M|        }
 1065|       |
 1066|       |        /*1.4//++imageCount; */
 1067|       |
 1068|    471|        if (!ReadOK(fd, buf, 9)) {
  ------------------
  |  |   57|    471|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1068:13): [True: 5, False: 466]
  ------------------
 1069|      5|            return 0;
 1070|      5|        }
 1071|       |
 1072|    466|        useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
  ------------------
  |  |   55|    466|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1073|       |
 1074|    466|        bitPixel = 1 << ((buf[8] & 0x07) + 1);
 1075|    466|        left = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    466|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1076|    466|        top = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    466|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1077|    466|        width = LM_to_uint(buf[4], buf[5]);
  ------------------
  |  |   59|    466|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1078|    466|        height = LM_to_uint(buf[6], buf[7]);
  ------------------
  |  |   59|    466|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1079|       |
 1080|    466|        if (((left + width) > screen_width) || ((top + height) > screen_height)) {
  ------------------
  |  Branch (1080:13): [True: 20, False: 446]
  |  Branch (1080:48): [True: 18, False: 428]
  ------------------
 1081|     38|            if (VERBOSE) {
  ------------------
  |  |   37|     38|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 38]
  |  |  ------------------
  ------------------
 1082|      0|                printf("Frame is not confined to screen dimension.\n");
 1083|      0|            }
 1084|     38|            return 0;
 1085|     38|        }
 1086|       |
 1087|    428|        if (!(im = gdImageCreate(width, height))) {
  ------------------
  |  Branch (1087:13): [True: 32, False: 396]
  ------------------
 1088|     32|            return 0;
 1089|     32|        }
 1090|       |
 1091|    396|        im->interlace = BitSet(buf[8], INTERLACE);
  ------------------
  |  |   55|    396|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1092|    396|        if (!useGlobalColormap) {
  ------------------
  |  Branch (1092:13): [True: 27, False: 369]
  ------------------
 1093|     27|            if (ReadColorMap(fd, bitPixel, localColorMap)) {
  ------------------
  |  Branch (1093:17): [True: 17, False: 10]
  ------------------
 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|     10|            if (!ReadImage(im, fd, width, height, localColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|     10|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1103:17): [True: 2, False: 8]
  ------------------
 1104|     10|                           &ZeroDataBlock)) {
 1105|      2|                gdImageDestroy(im);
 1106|      2|                return 0;
 1107|      2|            }
 1108|    369|        } else {
 1109|    369|            if (!haveGlobalColormap) {
  ------------------
  |  Branch (1109:17): [True: 368, False: 1]
  ------------------
 1110|       |                // Still a valid gif, apply simple default palette as per spec
 1111|    368|                ColorMap[CM_RED][1] = 0xff;
  ------------------
  |  |   46|    368|#define CM_RED 0
  ------------------
 1112|    368|                ColorMap[CM_GREEN][1] = 0xff;
  ------------------
  |  |   47|    368|#define CM_GREEN 1
  ------------------
 1113|    368|                ColorMap[CM_BLUE][1] = 0xff;
  ------------------
  |  |   48|    368|#define CM_BLUE 2
  ------------------
 1114|    368|            }
 1115|       |
 1116|       |            /* Keep legacy tolerance here as above; strict validation is used by
 1117|       |             * the animated GIF iterator.
 1118|       |             */
 1119|    369|            if (!ReadImage(im, fd, width, height, ColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|    369|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1119:17): [True: 19, False: 350]
  ------------------
 1120|    369|                           &ZeroDataBlock)) {
 1121|     19|                gdImageDestroy(im);
 1122|     19|                return 0;
 1123|     19|            }
 1124|    369|        }
 1125|       |
 1126|    358|        if (Transparent != (-1)) {
  ------------------
  |  Branch (1126:13): [True: 14, False: 344]
  ------------------
 1127|     14|            gdImageColorTransparent(im, Transparent);
 1128|     14|        }
 1129|       |
 1130|    358|        goto terminated;
 1131|    396|    }
 1132|       |
 1133|    360|terminated:
 1134|       |    /* Terminator before any image was declared! */
 1135|    360|    if (!im) {
  ------------------
  |  Branch (1135:9): [True: 2, False: 358]
  ------------------
 1136|      2|        return 0;
 1137|      2|    }
 1138|       |
 1139|       |    /* Check for open colors at the end, so
 1140|       |     * we can reduce colorsTotal and ultimately
 1141|       |     * BitsPerPixel */
 1142|  75.6k|    for (i = im->colorsTotal - 1; i >= 0; i--) {
  ------------------
  |  Branch (1142:35): [True: 75.5k, False: 42]
  ------------------
 1143|  75.5k|        if (im->open[i]) {
  ------------------
  |  Branch (1143:13): [True: 75.2k, False: 316]
  ------------------
 1144|  75.2k|            im->colorsTotal--;
 1145|  75.2k|        } else {
 1146|    316|            break;
 1147|    316|        }
 1148|  75.5k|    }
 1149|       |
 1150|    358|    if (!im->colorsTotal) {
  ------------------
  |  Branch (1150:9): [True: 42, False: 316]
  ------------------
 1151|     42|        gdImageDestroy(im);
 1152|     42|        return 0;
 1153|     42|    }
 1154|       |
 1155|    316|    return im;
 1156|    358|}
gd_gif_in.c:GetDataBlock:
 1226|   169k|{
 1227|   169k|    int rv, i;
 1228|       |
 1229|   169k|    rv = GetDataBlock_(fd, buf, ZeroDataBlockP);
 1230|       |
 1231|   169k|    if (VERBOSE) {
  ------------------
  |  |   37|   169k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 169k]
  |  |  ------------------
  ------------------
 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|   169k|    return rv;
 1243|   169k|}
gd_gif_in.c:GetDataBlock_:
 1209|   169k|{
 1210|   169k|    unsigned char count;
 1211|       |
 1212|   169k|    if (!ReadOK(fd, &count, 1)) {
  ------------------
  |  |   57|   169k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1212:9): [True: 448, False: 169k]
  ------------------
 1213|    448|        return -1;
 1214|    448|    }
 1215|       |
 1216|   169k|    *ZeroDataBlockP = count == 0;
 1217|       |
 1218|   169k|    if ((count != 0) && (!ReadOK(fd, buf, count))) {
  ------------------
  |  |   57|   145k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1218:9): [True: 145k, False: 23.9k]
  |  Branch (1218:25): [True: 79, False: 145k]
  ------------------
 1219|     79|        return -1;
 1220|     79|    }
 1221|       |
 1222|   169k|    return count;
 1223|   169k|}
gd_gif_in.c:ReadColorMap:
 1159|     50|{
 1160|     50|    int i;
 1161|     50|    unsigned char rgb[3];
 1162|       |
 1163|  1.32k|    for (i = 0; i < number; ++i) {
  ------------------
  |  Branch (1163:17): [True: 1.31k, False: 14]
  ------------------
 1164|  1.31k|        if (!ReadOK(fd, rgb, sizeof(rgb))) {
  ------------------
  |  |   57|  1.31k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1164:13): [True: 36, False: 1.27k]
  ------------------
 1165|     36|            return TRUE;
  ------------------
  |  |   43|     36|#define TRUE 1
  ------------------
 1166|     36|        }
 1167|       |
 1168|  1.27k|        buffer[CM_RED][i] = rgb[0];
  ------------------
  |  |   46|  1.27k|#define CM_RED 0
  ------------------
 1169|  1.27k|        buffer[CM_GREEN][i] = rgb[1];
  ------------------
  |  |   47|  1.27k|#define CM_GREEN 1
  ------------------
 1170|  1.27k|        buffer[CM_BLUE][i] = rgb[2];
  ------------------
  |  |   48|  1.27k|#define CM_BLUE 2
  ------------------
 1171|  1.27k|    }
 1172|       |
 1173|     14|    return FALSE;
  ------------------
  |  |   44|     14|#define FALSE 0
  ------------------
 1174|     50|}
gd_gif_in.c:DoExtension:
 1177|  21.4k|{
 1178|  21.4k|    unsigned char buf[256];
 1179|       |
 1180|  21.4k|    switch (label) {
 1181|  17.4k|    case 0xf9:             /* Graphic Control Extension */
  ------------------
  |  Branch (1181:5): [True: 17.4k, False: 3.98k]
  ------------------
 1182|  17.4k|        memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
 1183|  17.4k|        (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|  17.4k|        if ((buf[0] & 0x1) != 0) {
  ------------------
  |  Branch (1189:13): [True: 11.4k, False: 6.02k]
  ------------------
 1190|  11.4k|            *Transparent = buf[3];
 1191|  11.4k|        }
 1192|       |
 1193|  56.4k|        while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1193:16): [True: 38.9k, False: 17.4k]
  ------------------
 1194|  38.9k|            ;
 1195|       |
 1196|  17.4k|        return FALSE;
  ------------------
  |  |   44|  17.4k|#define FALSE 0
  ------------------
 1197|       |
 1198|  3.98k|    default:
  ------------------
  |  Branch (1198:5): [True: 3.98k, False: 17.4k]
  ------------------
 1199|  3.98k|        break;
 1200|  21.4k|    }
 1201|       |
 1202|  88.8k|    while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1202:12): [True: 84.8k, False: 3.98k]
  ------------------
 1203|  84.8k|        ;
 1204|       |
 1205|  3.98k|    return FALSE;
  ------------------
  |  |   44|  3.98k|#define FALSE 0
  ------------------
 1206|  21.4k|}
gd_gif_in.c:ReadImage:
 1473|    379|{
 1474|    379|    unsigned char c;
 1475|    379|    int xpos = 0, ypos = 0, pass = 0;
 1476|    379|    int v, i;
 1477|    379|    LZW_STATIC_DATA sd;
 1478|       |
 1479|       |    /* Initialize the Compression routines */
 1480|    379|    if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|    379|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1480:9): [True: 16, False: 363]
  ------------------
 1481|     16|        return 0;
 1482|     16|    }
 1483|       |
 1484|    363|    if (c > MAX_LWZ_BITS) {
  ------------------
  |  |   50|    363|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1484:9): [True: 5, False: 358]
  ------------------
 1485|      5|        return 0;
 1486|      5|    }
 1487|       |
 1488|       |    /* Stash the color map into the image */
 1489|  92.0k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  92.0k|#define gdMaxColors 256
  ------------------
  |  Branch (1489:17): [True: 91.6k, False: 358]
  ------------------
 1490|  91.6k|        im->red[i] = cmap[CM_RED][i];
  ------------------
  |  |   46|  91.6k|#define CM_RED 0
  ------------------
 1491|  91.6k|        im->green[i] = cmap[CM_GREEN][i];
  ------------------
  |  |   47|  91.6k|#define CM_GREEN 1
  ------------------
 1492|  91.6k|        im->blue[i] = cmap[CM_BLUE][i];
  ------------------
  |  |   48|  91.6k|#define CM_BLUE 2
  ------------------
 1493|  91.6k|        im->open[i] = 1;
 1494|  91.6k|    }
 1495|       |
 1496|       |    /* Many (perhaps most) of these colors will remain marked open. */
 1497|    358|    im->colorsTotal = gdMaxColors;
  ------------------
  |  |  117|    358|#define gdMaxColors 256
  ------------------
 1498|    358|    if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
  ------------------
  |  |   43|    358|#define TRUE 1
  ------------------
  |  Branch (1498:9): [True: 0, False: 358]
  ------------------
 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|   278k|    while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   278k|#define FALSE 0
  ------------------
  |  Branch (1512:12): [True: 277k, False: 344]
  ------------------
 1513|   277k|        if (colorCount > 0 && v >= colorCount) {
  ------------------
  |  Branch (1513:13): [True: 0, False: 277k]
  |  Branch (1513:31): [True: 0, False: 0]
  ------------------
 1514|      0|            return 0;
 1515|      0|        }
 1516|   277k|        if (v >= gdMaxColors) {
  ------------------
  |  |  117|   277k|#define gdMaxColors 256
  ------------------
  |  Branch (1516:13): [True: 80.5k, False: 197k]
  ------------------
 1517|  80.5k|            v = 0;
 1518|  80.5k|        }
 1519|       |
 1520|       |        /* This how we recognize which colors are actually used. */
 1521|   277k|        if (im->open[v]) {
  ------------------
  |  Branch (1521:13): [True: 2.20k, False: 275k]
  ------------------
 1522|  2.20k|            im->open[v] = 0;
 1523|  2.20k|        }
 1524|       |
 1525|   277k|        gdImageSetPixel(im, xpos, ypos, v);
 1526|       |
 1527|   277k|        ++xpos;
 1528|   277k|        if (xpos == len) {
  ------------------
  |  Branch (1528:13): [True: 28.1k, False: 249k]
  ------------------
 1529|  28.1k|            xpos = 0;
 1530|  28.1k|            if (interlace) {
  ------------------
  |  Branch (1530:17): [True: 21.2k, False: 6.90k]
  ------------------
 1531|  21.2k|                switch (pass) {
  ------------------
  |  Branch (1531:25): [True: 21.2k, False: 0]
  ------------------
 1532|  7.14k|                case 0:
  ------------------
  |  Branch (1532:17): [True: 7.14k, False: 14.1k]
  ------------------
 1533|  10.3k|                case 1:
  ------------------
  |  Branch (1533:17): [True: 3.18k, False: 18.0k]
  ------------------
 1534|  10.3k|                    ypos += 8;
 1535|  10.3k|                    break;
 1536|  5.83k|                case 2:
  ------------------
  |  Branch (1536:17): [True: 5.83k, False: 15.4k]
  ------------------
 1537|  5.83k|                    ypos += 4;
 1538|  5.83k|                    break;
 1539|  5.10k|                case 3:
  ------------------
  |  Branch (1539:17): [True: 5.10k, False: 16.1k]
  ------------------
 1540|  5.10k|                    ypos += 2;
 1541|  5.10k|                    break;
 1542|  21.2k|                }
 1543|       |
 1544|  21.2k|                if (ypos >= height) {
  ------------------
  |  Branch (1544:21): [True: 128, False: 21.1k]
  ------------------
 1545|    128|                    ++pass;
 1546|    128|                    switch (pass) {
 1547|     52|                    case 1:
  ------------------
  |  Branch (1547:21): [True: 52, False: 76]
  ------------------
 1548|     52|                        ypos = 4;
 1549|     52|                        break;
 1550|     43|                    case 2:
  ------------------
  |  Branch (1550:21): [True: 43, False: 85]
  ------------------
 1551|     43|                        ypos = 2;
 1552|     43|                        break;
 1553|     26|                    case 3:
  ------------------
  |  Branch (1553:21): [True: 26, False: 102]
  ------------------
 1554|     26|                        ypos = 1;
 1555|     26|                        break;
 1556|      7|                    default:
  ------------------
  |  Branch (1556:21): [True: 7, False: 121]
  ------------------
 1557|      7|                        goto fini;
 1558|    128|                    }
 1559|    128|                }
 1560|  21.2k|            } else {
 1561|  6.90k|                ++ypos;
 1562|  6.90k|            }
 1563|  28.1k|        }
 1564|       |
 1565|   277k|        if (ypos >= height) {
  ------------------
  |  Branch (1565:13): [True: 7, False: 277k]
  ------------------
 1566|      7|            break;
 1567|      7|        }
 1568|   277k|    }
 1569|       |
 1570|    358|fini:
 1571|    358|    if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >= 0) {
  ------------------
  |  |   44|    358|#define FALSE 0
  ------------------
  |  Branch (1571:9): [True: 24, False: 334]
  ------------------
 1572|       |        /* Ignore extra */
 1573|     24|    }
 1574|    358|    return 1;
 1575|    358|}
gd_gif_in.c:LWZReadByte:
 1459|   278k|{
 1460|   278k|    int rv;
 1461|       |
 1462|   278k|    rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
 1463|       |
 1464|   278k|    if (VERBOSE) {
  ------------------
  |  |   37|   278k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 278k]
  |  |  ------------------
  ------------------
 1465|      0|        printf("[LWZReadByte(,%d,%d) returning %d]\n", flag, input_code_size, rv);
 1466|      0|    }
 1467|       |
 1468|   278k|    return rv;
 1469|   278k|}
gd_gif_in.c:LWZReadByte_:
 1321|   278k|{
 1322|   278k|    int code, incode, i;
 1323|       |
 1324|   278k|    if (flag) {
  ------------------
  |  Branch (1324:9): [True: 358, False: 278k]
  ------------------
 1325|    358|        sd->set_code_size = input_code_size;
 1326|    358|        sd->code_size = sd->set_code_size + 1;
 1327|    358|        sd->clear_code = 1 << sd->set_code_size;
 1328|    358|        sd->end_code = sd->clear_code + 1;
 1329|    358|        sd->max_code_size = 2 * sd->clear_code;
 1330|    358|        sd->max_code = sd->clear_code + 2;
 1331|       |
 1332|    358|        GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
  ------------------
  |  |   43|    358|#define TRUE 1
  ------------------
 1333|       |
 1334|    358|        sd->fresh = TRUE;
  ------------------
  |  |   43|    358|#define TRUE 1
  ------------------
 1335|       |
 1336|   329k|        for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1336:21): [True: 328k, False: 358]
  ------------------
 1337|   328k|            sd->table[0][i] = 0;
 1338|   328k|            sd->table[1][i] = i;
 1339|   328k|        }
 1340|       |
 1341|  1.13M|        for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  1.13M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1341:16): [True: 1.13M, False: 358]
  ------------------
 1342|  1.13M|            sd->table[0][i] = sd->table[1][0] = 0;
 1343|  1.13M|        }
 1344|       |
 1345|    358|        sd->sp = sd->stack;
 1346|       |
 1347|    358|        return 0;
 1348|       |
 1349|   278k|    } else if (sd->fresh) {
  ------------------
  |  Branch (1349:16): [True: 358, False: 278k]
  ------------------
 1350|    358|        sd->fresh = FALSE;
  ------------------
  |  |   44|    358|#define FALSE 0
  ------------------
 1351|       |
 1352|    771|        do {
 1353|    771|            sd->firstcode = sd->oldcode =
 1354|    771|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|    771|#define FALSE 0
  ------------------
 1355|    771|        } while (sd->firstcode == sd->clear_code);
  ------------------
  |  Branch (1355:18): [True: 413, False: 358]
  ------------------
 1356|       |
 1357|    358|        return sd->firstcode;
 1358|    358|    }
 1359|       |
 1360|   278k|    if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1360:9): [True: 160k, False: 117k]
  ------------------
 1361|   160k|        return *--sd->sp;
 1362|   160k|    }
 1363|       |
 1364|   117k|    while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   117k|#define FALSE 0
  ------------------
  |  Branch (1364:12): [True: 117k, False: 549]
  ------------------
 1365|   117k|        if (code == sd->clear_code) {
  ------------------
  |  Branch (1365:13): [True: 4.19k, False: 112k]
  ------------------
 1366|  1.03M|            for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1366:25): [True: 1.02M, False: 4.19k]
  ------------------
 1367|  1.02M|                sd->table[0][i] = 0;
 1368|  1.02M|                sd->table[1][i] = i;
 1369|  1.02M|            }
 1370|       |
 1371|  16.1M|            for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  16.1M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1371:20): [True: 16.1M, False: 4.19k]
  ------------------
 1372|  16.1M|                sd->table[0][i] = sd->table[1][i] = 0;
 1373|  16.1M|            }
 1374|       |
 1375|  4.19k|            sd->code_size = sd->set_code_size + 1;
 1376|  4.19k|            sd->max_code_size = 2 * sd->clear_code;
 1377|  4.19k|            sd->max_code = sd->clear_code + 2;
 1378|  4.19k|            sd->sp = sd->stack;
 1379|  4.19k|            sd->firstcode = sd->oldcode =
 1380|  4.19k|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|  4.19k|#define FALSE 0
  ------------------
 1381|       |
 1382|  4.19k|            return sd->firstcode;
 1383|   112k|        } else if (code == sd->end_code) {
  ------------------
  |  Branch (1383:20): [True: 240, False: 112k]
  ------------------
 1384|    240|            int count;
 1385|    240|            unsigned char buf[260];
 1386|       |
 1387|    240|            if (*ZeroDataBlockP) {
  ------------------
  |  Branch (1387:17): [True: 3, False: 237]
  ------------------
 1388|      3|                return -2;
 1389|      3|            }
 1390|       |
 1391|  1.18k|            while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
  ------------------
  |  Branch (1391:20): [True: 948, False: 237]
  ------------------
 1392|    948|                ;
 1393|       |
 1394|    237|            if (count != 0) {
  ------------------
  |  Branch (1394:17): [True: 40, False: 197]
  ------------------
 1395|     40|                return -2;
 1396|     40|            }
 1397|    237|        }
 1398|       |
 1399|   112k|        incode = code;
 1400|       |
 1401|   112k|        if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   112k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   112k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1401:13): [True: 0, False: 112k]
  ------------------
 1402|       |            /* Bad compressed data stream */
 1403|      0|            return -1;
 1404|      0|        }
 1405|       |
 1406|   112k|        if (code >= sd->max_code) {
  ------------------
  |  Branch (1406:13): [True: 30.3k, False: 82.5k]
  ------------------
 1407|  30.3k|            *sd->sp++ = sd->firstcode;
 1408|  30.3k|            code = sd->oldcode;
 1409|  30.3k|        }
 1410|       |
 1411|   251k|        while (code >= sd->clear_code) {
  ------------------
  |  Branch (1411:16): [True: 138k, False: 112k]
  ------------------
 1412|   138k|            if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   138k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   138k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1412:17): [True: 1, False: 138k]
  ------------------
 1413|       |                /* Bad compressed data stream */
 1414|      1|                return -1;
 1415|      1|            }
 1416|   138k|            if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   138k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1416:17): [True: 6, False: 138k]
  ------------------
 1417|       |                /* Corrupted code */
 1418|      6|                return -1;
 1419|      6|            }
 1420|       |
 1421|   138k|            *sd->sp++ = sd->table[1][code];
 1422|       |
 1423|   138k|            if (code == sd->table[0][code]) {
  ------------------
  |  Branch (1423:17): [True: 8.19k, False: 130k]
  ------------------
 1424|       |                /* Oh well */
 1425|  8.19k|            }
 1426|       |
 1427|   138k|            code = sd->table[0][code];
 1428|   138k|        }
 1429|   112k|        if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   112k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1429:13): [True: 0, False: 112k]
  ------------------
 1430|       |            /* Corrupted code */
 1431|      0|            return -1;
 1432|      0|        }
 1433|       |
 1434|   112k|        *sd->sp++ = sd->firstcode = sd->table[1][code];
 1435|       |
 1436|   112k|        if ((code = sd->max_code) < (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   112k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1436:13): [True: 112k, False: 794]
  ------------------
 1437|   112k|            sd->table[0][code] = sd->oldcode;
 1438|   112k|            sd->table[1][code] = sd->firstcode;
 1439|   112k|            ++sd->max_code;
 1440|       |
 1441|   112k|            if ((sd->max_code >= sd->max_code_size) && (sd->max_code_size < (1 << MAX_LWZ_BITS))) {
  ------------------
  |  |   50|  4.49k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1441:17): [True: 4.49k, False: 107k]
  |  Branch (1441:56): [True: 4.45k, False: 36]
  ------------------
 1442|  4.45k|                sd->max_code_size *= 2;
 1443|  4.45k|                ++sd->code_size;
 1444|  4.45k|            }
 1445|   112k|        }
 1446|       |
 1447|   112k|        sd->oldcode = incode;
 1448|       |
 1449|   112k|        if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1449:13): [True: 112k, False: 0]
  ------------------
 1450|   112k|            return *--sd->sp;
 1451|   112k|        }
 1452|   112k|    }
 1453|       |
 1454|    549|    return code;
 1455|   117k|}
gd_gif_in.c:GetCode:
 1307|   122k|{
 1308|   122k|    int rv;
 1309|       |
 1310|   122k|    rv = GetCode_(fd, scd, code_size, flag, ZeroDataBlockP);
 1311|       |
 1312|   122k|    if (VERBOSE) {
  ------------------
  |  |   37|   122k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 122k]
  |  |  ------------------
  ------------------
 1313|      0|        printf("[GetCode(,%d,%d) returning %d]\n", code_size, flag, rv);
 1314|      0|    }
 1315|       |
 1316|   122k|    return rv;
 1317|   122k|}
gd_gif_in.c:GetCode_:
 1247|   122k|{
 1248|   122k|    int i, j, ret;
 1249|   122k|    int count;
 1250|       |
 1251|   122k|    if (flag) {
  ------------------
  |  Branch (1251:9): [True: 358, False: 122k]
  ------------------
 1252|    358|        scd->curbit = 0;
 1253|    358|        scd->lastbit = 0;
 1254|    358|        scd->last_byte = 2;
 1255|    358|        scd->done = FALSE;
  ------------------
  |  |   44|    358|#define FALSE 0
  ------------------
 1256|    358|        return 0;
 1257|    358|    }
 1258|       |
 1259|   122k|    if ((scd->curbit + code_size) >= scd->lastbit) {
  ------------------
  |  Branch (1259:9): [True: 6.02k, False: 116k]
  ------------------
 1260|  6.02k|        if (scd->done) {
  ------------------
  |  Branch (1260:13): [True: 410, False: 5.61k]
  ------------------
 1261|    410|            if (scd->curbit >= scd->lastbit) {
  ------------------
  |  Branch (1261:17): [True: 245, False: 165]
  ------------------
 1262|       |                /* Oh well */
 1263|    245|            }
 1264|    410|            return -1;
 1265|    410|        }
 1266|       |
 1267|  5.61k|        scd->buf[0] = scd->buf[scd->last_byte - 2];
 1268|  5.61k|        scd->buf[1] = scd->buf[scd->last_byte - 1];
 1269|  5.61k|        scd->last_byte = 2;
 1270|  5.61k|        scd->curbit = (scd->curbit - scd->lastbit) + 16;
 1271|  5.61k|        scd->lastbit = 16;
 1272|       |
 1273|  5.98k|        do {
 1274|  5.98k|            if (scd->last_byte > (CSD_BUF_SIZE - 255)) {
  ------------------
  |  |   85|  5.98k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1274:17): [True: 0, False: 5.98k]
  ------------------
 1275|      0|                return -1;
 1276|      0|            }
 1277|       |
 1278|  5.98k|            if ((count = GetDataBlock(fd, &scd->buf[scd->last_byte], ZeroDataBlockP)) <= 0) {
  ------------------
  |  Branch (1278:17): [True: 326, False: 5.66k]
  ------------------
 1279|    326|                scd->done = TRUE;
  ------------------
  |  |   43|    326|#define TRUE 1
  ------------------
 1280|    326|                break;
 1281|    326|            }
 1282|       |
 1283|  5.66k|            scd->last_byte += count;
 1284|  5.66k|            scd->lastbit += count * 8;
 1285|  5.66k|        } while ((scd->curbit + code_size) > scd->lastbit);
  ------------------
  |  Branch (1285:18): [True: 377, False: 5.28k]
  ------------------
 1286|  5.61k|    }
 1287|       |
 1288|   122k|    if ((scd->curbit + code_size) > scd->lastbit) {
  ------------------
  |  Branch (1288:9): [True: 218, False: 122k]
  ------------------
 1289|    218|        return -1;
 1290|    218|    }
 1291|       |
 1292|   122k|    if ((scd->curbit + code_size - 1) >= (CSD_BUF_SIZE * 8)) {
  ------------------
  |  |   85|   122k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1292:9): [True: 0, False: 122k]
  ------------------
 1293|      0|        ret = -1;
 1294|   122k|    } else {
 1295|   122k|        ret = 0;
 1296|  1.39M|        for (i = scd->curbit, j = 0; j < code_size; ++i, ++j) {
  ------------------
  |  Branch (1296:38): [True: 1.26M, False: 122k]
  ------------------
 1297|  1.26M|            ret |= ((scd->buf[i / 8] & (1 << (i % 8))) != 0) << j;
 1298|  1.26M|        }
 1299|   122k|    }
 1300|       |
 1301|   122k|    scd->curbit += code_size;
 1302|       |
 1303|   122k|    return ret;
 1304|   122k|}

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

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

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

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

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

