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

gdImageCreateFromGifPtr:
  968|    763|{
  969|    763|    gdImagePtr im;
  970|    763|    gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
  971|    763|    if (!in) {
  ------------------
  |  Branch (971:9): [True: 0, False: 763]
  ------------------
  972|      0|        return 0;
  973|      0|    }
  974|    763|    im = gdImageCreateFromGifCtx(in);
  975|    763|    in->gd_free(in);
  976|    763|    return im;
  977|    763|}
gdImageCreateFromGifCtx:
  980|    763|{
  981|    763|    int BitPixel;
  982|       |#if 0
  983|       |	int ColorResolution;
  984|       |	int Background;
  985|       |	int AspectRatio;
  986|       |#endif
  987|    763|    int Transparent = (-1);
  988|    763|    unsigned char buf[16];
  989|    763|    unsigned char c;
  990|    763|    unsigned char ColorMap[3][MAXCOLORMAPSIZE];
  991|    763|    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
  992|    763|    int imw, imh, screen_width, screen_height;
  993|    763|    int useGlobalColormap;
  994|    763|    int bitPixel, i;
  995|       |    /*1.4//int             imageCount = 0; */
  996|       |    /* 2.0.28: threadsafe storage */
  997|    763|    int ZeroDataBlock = FALSE;
  ------------------
  |  |   44|    763|#define FALSE 0
  ------------------
  998|    763|    int haveGlobalColormap;
  999|       |
 1000|    763|    gdImagePtr im = 0;
 1001|       |
 1002|    763|    memset(ColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    763|#define MAXCOLORMAPSIZE 256
  ------------------
 1003|    763|    memset(localColorMap, 0, 3 * MAXCOLORMAPSIZE);
  ------------------
  |  |   41|    763|#define MAXCOLORMAPSIZE 256
  ------------------
 1004|       |
 1005|    763|    if (!ReadOK(fd, buf, 6)) {
  ------------------
  |  |   57|    763|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1005:9): [True: 4, False: 759]
  ------------------
 1006|      4|        return 0;
 1007|      4|    }
 1008|       |
 1009|    759|    if (strncmp((char *)buf, "GIF", 3) != 0) {
  ------------------
  |  Branch (1009:9): [True: 33, False: 726]
  ------------------
 1010|     33|        return 0;
 1011|     33|    }
 1012|       |
 1013|    726|    if (memcmp((char *)buf + 3, "87a", 3) == 0) {
  ------------------
  |  Branch (1013:9): [True: 249, False: 477]
  ------------------
 1014|       |        /* GIF87a */
 1015|    477|    } else if (memcmp((char *)buf + 3, "89a", 3) == 0) {
  ------------------
  |  Branch (1015:16): [True: 447, False: 30]
  ------------------
 1016|       |        /* GIF89a */
 1017|    447|    } else {
 1018|     30|        return 0;
 1019|     30|    }
 1020|       |
 1021|    696|    if (!ReadOK(fd, buf, 7)) {
  ------------------
  |  |   57|    696|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1021:9): [True: 7, False: 689]
  ------------------
 1022|      7|        return 0;
 1023|      7|    }
 1024|       |
 1025|    689|    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|    689|    screen_width = imw = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    689|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1032|    689|    screen_height = imh = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    689|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1033|       |
 1034|    689|    haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
  ------------------
  |  |   55|    689|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1035|    689|    if (haveGlobalColormap) {
  ------------------
  |  Branch (1035:9): [True: 24, False: 665]
  ------------------
 1036|     24|        if (ReadColorMap(fd, BitPixel, ColorMap)) {
  ------------------
  |  Branch (1036:13): [True: 18, False: 6]
  ------------------
 1037|     18|            return 0;
 1038|     18|        }
 1039|     24|    }
 1040|       |
 1041|  4.52M|    for (;;) {
 1042|  4.52M|        int top, left;
 1043|  4.52M|        int width, height;
 1044|       |
 1045|  4.52M|        if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  4.52M|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1045:13): [True: 200, False: 4.52M]
  ------------------
 1046|    200|            return 0;
 1047|    200|        }
 1048|       |
 1049|  4.52M|        if (c == ';') { /* GIF terminator */
  ------------------
  |  Branch (1049:13): [True: 1, False: 4.52M]
  ------------------
 1050|      1|            goto terminated;
 1051|      1|        }
 1052|       |
 1053|  4.52M|        if (c == '!') { /* Extension */
  ------------------
  |  Branch (1053:13): [True: 21.2k, False: 4.50M]
  ------------------
 1054|  21.2k|            if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|  21.2k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1054:17): [True: 1, False: 21.2k]
  ------------------
 1055|      1|                return 0;
 1056|      1|            }
 1057|       |
 1058|  21.2k|            DoExtension(fd, c, &Transparent, &ZeroDataBlock);
 1059|  21.2k|            continue;
 1060|  21.2k|        }
 1061|       |
 1062|  4.50M|        if (c != ',') { /* Not a valid start character */
  ------------------
  |  Branch (1062:13): [True: 4.50M, False: 469]
  ------------------
 1063|  4.50M|            continue;
 1064|  4.50M|        }
 1065|       |
 1066|       |        /*1.4//++imageCount; */
 1067|       |
 1068|    469|        if (!ReadOK(fd, buf, 9)) {
  ------------------
  |  |   57|    469|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1068:13): [True: 6, False: 463]
  ------------------
 1069|      6|            return 0;
 1070|      6|        }
 1071|       |
 1072|    463|        useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
  ------------------
  |  |   55|    463|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1073|       |
 1074|    463|        bitPixel = 1 << ((buf[8] & 0x07) + 1);
 1075|    463|        left = LM_to_uint(buf[0], buf[1]);
  ------------------
  |  |   59|    463|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1076|    463|        top = LM_to_uint(buf[2], buf[3]);
  ------------------
  |  |   59|    463|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1077|    463|        width = LM_to_uint(buf[4], buf[5]);
  ------------------
  |  |   59|    463|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1078|    463|        height = LM_to_uint(buf[6], buf[7]);
  ------------------
  |  |   59|    463|#define LM_to_uint(a, b) (((b) << 8) | (a))
  ------------------
 1079|       |
 1080|    463|        if (((left + width) > screen_width) || ((top + height) > screen_height)) {
  ------------------
  |  Branch (1080:13): [True: 20, False: 443]
  |  Branch (1080:48): [True: 18, False: 425]
  ------------------
 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|    425|        if (!(im = gdImageCreate(width, height))) {
  ------------------
  |  Branch (1087:13): [True: 28, False: 397]
  ------------------
 1088|     28|            return 0;
 1089|     28|        }
 1090|       |
 1091|    397|        im->interlace = BitSet(buf[8], INTERLACE);
  ------------------
  |  |   55|    397|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
 1092|    397|        if (!useGlobalColormap) {
  ------------------
  |  Branch (1092:13): [True: 27, False: 370]
  ------------------
 1093|     27|            if (ReadColorMap(fd, bitPixel, localColorMap)) {
  ------------------
  |  Branch (1093:17): [True: 21, False: 6]
  ------------------
 1094|     21|                gdImageDestroy(im);
 1095|     21|                return 0;
 1096|     21|            }
 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|      6|            if (!ReadImage(im, fd, width, height, localColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|      6|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1103:17): [True: 1, False: 5]
  ------------------
 1104|      6|                           &ZeroDataBlock)) {
 1105|      1|                gdImageDestroy(im);
 1106|      1|                return 0;
 1107|      1|            }
 1108|    370|        } else {
 1109|    370|            if (!haveGlobalColormap) {
  ------------------
  |  Branch (1109:17): [True: 369, False: 1]
  ------------------
 1110|       |                // Still a valid gif, apply simple default palette as per spec
 1111|    369|                ColorMap[CM_RED][1] = 0xff;
  ------------------
  |  |   46|    369|#define CM_RED 0
  ------------------
 1112|    369|                ColorMap[CM_GREEN][1] = 0xff;
  ------------------
  |  |   47|    369|#define CM_GREEN 1
  ------------------
 1113|    369|                ColorMap[CM_BLUE][1] = 0xff;
  ------------------
  |  |   48|    369|#define CM_BLUE 2
  ------------------
 1114|    369|            }
 1115|       |
 1116|       |            /* Keep legacy tolerance here as above; strict validation is used by
 1117|       |             * the animated GIF iterator.
 1118|       |             */
 1119|    370|            if (!ReadImage(im, fd, width, height, ColorMap, 0, BitSet(buf[8], INTERLACE),
  ------------------
  |  |   55|    370|#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
  ------------------
  |  Branch (1119:17): [True: 18, False: 352]
  ------------------
 1120|    370|                           &ZeroDataBlock)) {
 1121|     18|                gdImageDestroy(im);
 1122|     18|                return 0;
 1123|     18|            }
 1124|    370|        }
 1125|       |
 1126|    357|        if (Transparent != (-1)) {
  ------------------
  |  Branch (1126:13): [True: 16, False: 341]
  ------------------
 1127|     16|            gdImageColorTransparent(im, Transparent);
 1128|     16|        }
 1129|       |
 1130|    357|        goto terminated;
 1131|    397|    }
 1132|       |
 1133|    358|terminated:
 1134|       |    /* Terminator before any image was declared! */
 1135|    358|    if (!im) {
  ------------------
  |  Branch (1135:9): [True: 1, False: 357]
  ------------------
 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.2k|    for (i = im->colorsTotal - 1; i >= 0; i--) {
  ------------------
  |  Branch (1142:35): [True: 76.2k, False: 44]
  ------------------
 1143|  76.2k|        if (im->open[i]) {
  ------------------
  |  Branch (1143:13): [True: 75.8k, False: 313]
  ------------------
 1144|  75.8k|            im->colorsTotal--;
 1145|  75.8k|        } else {
 1146|    313|            break;
 1147|    313|        }
 1148|  76.2k|    }
 1149|       |
 1150|    357|    if (!im->colorsTotal) {
  ------------------
  |  Branch (1150:9): [True: 44, False: 313]
  ------------------
 1151|     44|        gdImageDestroy(im);
 1152|     44|        return 0;
 1153|     44|    }
 1154|       |
 1155|    313|    return im;
 1156|    357|}
gd_gif_in.c:GetDataBlock:
 1226|   162k|{
 1227|   162k|    int rv, i;
 1228|       |
 1229|   162k|    rv = GetDataBlock_(fd, buf, ZeroDataBlockP);
 1230|       |
 1231|   162k|    if (VERBOSE) {
  ------------------
  |  |   37|   162k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 162k]
  |  |  ------------------
  ------------------
 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|   162k|    return rv;
 1243|   162k|}
gd_gif_in.c:GetDataBlock_:
 1209|   162k|{
 1210|   162k|    unsigned char count;
 1211|       |
 1212|   162k|    if (!ReadOK(fd, &count, 1)) {
  ------------------
  |  |   57|   162k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1212:9): [True: 453, False: 161k]
  ------------------
 1213|    453|        return -1;
 1214|    453|    }
 1215|       |
 1216|   161k|    *ZeroDataBlockP = count == 0;
 1217|       |
 1218|   161k|    if ((count != 0) && (!ReadOK(fd, buf, count))) {
  ------------------
  |  |   57|   138k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1218:9): [True: 138k, False: 23.7k]
  |  Branch (1218:25): [True: 86, False: 138k]
  ------------------
 1219|     86|        return -1;
 1220|     86|    }
 1221|       |
 1222|   161k|    return count;
 1223|   161k|}
gd_gif_in.c:ReadColorMap:
 1159|     51|{
 1160|     51|    int i;
 1161|     51|    unsigned char rgb[3];
 1162|       |
 1163|  1.06k|    for (i = 0; i < number; ++i) {
  ------------------
  |  Branch (1163:17): [True: 1.05k, False: 12]
  ------------------
 1164|  1.05k|        if (!ReadOK(fd, rgb, sizeof(rgb))) {
  ------------------
  |  |   57|  1.05k|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1164:13): [True: 39, False: 1.01k]
  ------------------
 1165|     39|            return TRUE;
  ------------------
  |  |   43|     39|#define TRUE 1
  ------------------
 1166|     39|        }
 1167|       |
 1168|  1.01k|        buffer[CM_RED][i] = rgb[0];
  ------------------
  |  |   46|  1.01k|#define CM_RED 0
  ------------------
 1169|  1.01k|        buffer[CM_GREEN][i] = rgb[1];
  ------------------
  |  |   47|  1.01k|#define CM_GREEN 1
  ------------------
 1170|  1.01k|        buffer[CM_BLUE][i] = rgb[2];
  ------------------
  |  |   48|  1.01k|#define CM_BLUE 2
  ------------------
 1171|  1.01k|    }
 1172|       |
 1173|     12|    return FALSE;
  ------------------
  |  |   44|     12|#define FALSE 0
  ------------------
 1174|     51|}
gd_gif_in.c:DoExtension:
 1177|  21.2k|{
 1178|  21.2k|    unsigned char buf[256];
 1179|       |
 1180|  21.2k|    switch (label) {
 1181|  17.0k|    case 0xf9:             /* Graphic Control Extension */
  ------------------
  |  Branch (1181:5): [True: 17.0k, False: 4.22k]
  ------------------
 1182|  17.0k|        memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
 1183|  17.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|  17.0k|        if ((buf[0] & 0x1) != 0) {
  ------------------
  |  Branch (1189:13): [True: 11.2k, False: 5.83k]
  ------------------
 1190|  11.2k|            *Transparent = buf[3];
 1191|  11.2k|        }
 1192|       |
 1193|  54.5k|        while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1193:16): [True: 37.4k, False: 17.0k]
  ------------------
 1194|  37.4k|            ;
 1195|       |
 1196|  17.0k|        return FALSE;
  ------------------
  |  |   44|  17.0k|#define FALSE 0
  ------------------
 1197|       |
 1198|  4.22k|    default:
  ------------------
  |  Branch (1198:5): [True: 4.22k, False: 17.0k]
  ------------------
 1199|  4.22k|        break;
 1200|  21.2k|    }
 1201|       |
 1202|  86.4k|    while (GetDataBlock(fd, (unsigned char *)buf, ZeroDataBlockP) > 0)
  ------------------
  |  Branch (1202:12): [True: 82.2k, False: 4.22k]
  ------------------
 1203|  82.2k|        ;
 1204|       |
 1205|  4.22k|    return FALSE;
  ------------------
  |  |   44|  4.22k|#define FALSE 0
  ------------------
 1206|  21.2k|}
gd_gif_in.c:ReadImage:
 1473|    376|{
 1474|    376|    unsigned char c;
 1475|    376|    int xpos = 0, ypos = 0, pass = 0;
 1476|    376|    int v, i;
 1477|    376|    LZW_STATIC_DATA sd;
 1478|       |
 1479|       |    /* Initialize the Compression routines */
 1480|    376|    if (!ReadOK(fd, &c, 1)) {
  ------------------
  |  |   57|    376|#define ReadOK(file, buffer, len) (gdGetBuf(buffer, len, file) == len)
  ------------------
  |  Branch (1480:9): [True: 14, False: 362]
  ------------------
 1481|     14|        return 0;
 1482|     14|    }
 1483|       |
 1484|    362|    if (c > MAX_LWZ_BITS) {
  ------------------
  |  |   50|    362|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1484:9): [True: 5, False: 357]
  ------------------
 1485|      5|        return 0;
 1486|      5|    }
 1487|       |
 1488|       |    /* Stash the color map into the image */
 1489|  91.7k|    for (i = 0; (i < gdMaxColors); i++) {
  ------------------
  |  |  117|  91.7k|#define gdMaxColors 256
  ------------------
  |  Branch (1489:17): [True: 91.3k, False: 357]
  ------------------
 1490|  91.3k|        im->red[i] = cmap[CM_RED][i];
  ------------------
  |  |   46|  91.3k|#define CM_RED 0
  ------------------
 1491|  91.3k|        im->green[i] = cmap[CM_GREEN][i];
  ------------------
  |  |   47|  91.3k|#define CM_GREEN 1
  ------------------
 1492|  91.3k|        im->blue[i] = cmap[CM_BLUE][i];
  ------------------
  |  |   48|  91.3k|#define CM_BLUE 2
  ------------------
 1493|  91.3k|        im->open[i] = 1;
 1494|  91.3k|    }
 1495|       |
 1496|       |    /* Many (perhaps most) of these colors will remain marked open. */
 1497|    357|    im->colorsTotal = gdMaxColors;
  ------------------
  |  |  117|    357|#define gdMaxColors 256
  ------------------
 1498|    357|    if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
  ------------------
  |  |   43|    357|#define TRUE 1
  ------------------
  |  Branch (1498:9): [True: 0, False: 357]
  ------------------
 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|   264k|    while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   264k|#define FALSE 0
  ------------------
  |  Branch (1512:12): [True: 264k, False: 349]
  ------------------
 1513|   264k|        if (colorCount > 0 && v >= colorCount) {
  ------------------
  |  Branch (1513:13): [True: 0, False: 264k]
  |  Branch (1513:31): [True: 0, False: 0]
  ------------------
 1514|      0|            return 0;
 1515|      0|        }
 1516|   264k|        if (v >= gdMaxColors) {
  ------------------
  |  |  117|   264k|#define gdMaxColors 256
  ------------------
  |  Branch (1516:13): [True: 79.5k, False: 184k]
  ------------------
 1517|  79.5k|            v = 0;
 1518|  79.5k|        }
 1519|       |
 1520|       |        /* This how we recognize which colors are actually used. */
 1521|   264k|        if (im->open[v]) {
  ------------------
  |  Branch (1521:13): [True: 2.12k, False: 262k]
  ------------------
 1522|  2.12k|            im->open[v] = 0;
 1523|  2.12k|        }
 1524|       |
 1525|   264k|        gdImageSetPixel(im, xpos, ypos, v);
 1526|       |
 1527|   264k|        ++xpos;
 1528|   264k|        if (xpos == len) {
  ------------------
  |  Branch (1528:13): [True: 27.3k, False: 237k]
  ------------------
 1529|  27.3k|            xpos = 0;
 1530|  27.3k|            if (interlace) {
  ------------------
  |  Branch (1530:17): [True: 24.1k, False: 3.17k]
  ------------------
 1531|  24.1k|                switch (pass) {
  ------------------
  |  Branch (1531:25): [True: 24.1k, False: 0]
  ------------------
 1532|  9.04k|                case 0:
  ------------------
  |  Branch (1532:17): [True: 9.04k, False: 15.0k]
  ------------------
 1533|  13.5k|                case 1:
  ------------------
  |  Branch (1533:17): [True: 4.54k, False: 19.5k]
  ------------------
 1534|  13.5k|                    ypos += 8;
 1535|  13.5k|                    break;
 1536|  5.58k|                case 2:
  ------------------
  |  Branch (1536:17): [True: 5.58k, False: 18.5k]
  ------------------
 1537|  5.58k|                    ypos += 4;
 1538|  5.58k|                    break;
 1539|  4.95k|                case 3:
  ------------------
  |  Branch (1539:17): [True: 4.95k, False: 19.1k]
  ------------------
 1540|  4.95k|                    ypos += 2;
 1541|  4.95k|                    break;
 1542|  24.1k|                }
 1543|       |
 1544|  24.1k|                if (ypos >= height) {
  ------------------
  |  Branch (1544:21): [True: 113, False: 24.0k]
  ------------------
 1545|    113|                    ++pass;
 1546|    113|                    switch (pass) {
 1547|     48|                    case 1:
  ------------------
  |  Branch (1547:21): [True: 48, False: 65]
  ------------------
 1548|     48|                        ypos = 4;
 1549|     48|                        break;
 1550|     38|                    case 2:
  ------------------
  |  Branch (1550:21): [True: 38, False: 75]
  ------------------
 1551|     38|                        ypos = 2;
 1552|     38|                        break;
 1553|     22|                    case 3:
  ------------------
  |  Branch (1553:21): [True: 22, False: 91]
  ------------------
 1554|     22|                        ypos = 1;
 1555|     22|                        break;
 1556|      5|                    default:
  ------------------
  |  Branch (1556:21): [True: 5, False: 108]
  ------------------
 1557|      5|                        goto fini;
 1558|    113|                    }
 1559|    113|                }
 1560|  24.1k|            } else {
 1561|  3.17k|                ++ypos;
 1562|  3.17k|            }
 1563|  27.3k|        }
 1564|       |
 1565|   264k|        if (ypos >= height) {
  ------------------
  |  Branch (1565:13): [True: 3, False: 264k]
  ------------------
 1566|      3|            break;
 1567|      3|        }
 1568|   264k|    }
 1569|       |
 1570|    357|fini:
 1571|    357|    if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >= 0) {
  ------------------
  |  |   44|    357|#define FALSE 0
  ------------------
  |  Branch (1571:9): [True: 22, False: 335]
  ------------------
 1572|       |        /* Ignore extra */
 1573|     22|    }
 1574|    357|    return 1;
 1575|    357|}
gd_gif_in.c:LWZReadByte:
 1459|   265k|{
 1460|   265k|    int rv;
 1461|       |
 1462|   265k|    rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
 1463|       |
 1464|   265k|    if (VERBOSE) {
  ------------------
  |  |   37|   265k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 265k]
  |  |  ------------------
  ------------------
 1465|      0|        printf("[LWZReadByte(,%d,%d) returning %d]\n", flag, input_code_size, rv);
 1466|      0|    }
 1467|       |
 1468|   265k|    return rv;
 1469|   265k|}
gd_gif_in.c:LWZReadByte_:
 1321|   265k|{
 1322|   265k|    int code, incode, i;
 1323|       |
 1324|   265k|    if (flag) {
  ------------------
  |  Branch (1324:9): [True: 357, False: 265k]
  ------------------
 1325|    357|        sd->set_code_size = input_code_size;
 1326|    357|        sd->code_size = sd->set_code_size + 1;
 1327|    357|        sd->clear_code = 1 << sd->set_code_size;
 1328|    357|        sd->end_code = sd->clear_code + 1;
 1329|    357|        sd->max_code_size = 2 * sd->clear_code;
 1330|    357|        sd->max_code = sd->clear_code + 2;
 1331|       |
 1332|    357|        GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
  ------------------
  |  |   43|    357|#define TRUE 1
  ------------------
 1333|       |
 1334|    357|        sd->fresh = TRUE;
  ------------------
  |  |   43|    357|#define TRUE 1
  ------------------
 1335|       |
 1336|   310k|        for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1336:21): [True: 310k, False: 357]
  ------------------
 1337|   310k|            sd->table[0][i] = 0;
 1338|   310k|            sd->table[1][i] = i;
 1339|   310k|        }
 1340|       |
 1341|  1.15M|        for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  1.15M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1341:16): [True: 1.15M, False: 357]
  ------------------
 1342|  1.15M|            sd->table[0][i] = sd->table[1][0] = 0;
 1343|  1.15M|        }
 1344|       |
 1345|    357|        sd->sp = sd->stack;
 1346|       |
 1347|    357|        return 0;
 1348|       |
 1349|   265k|    } else if (sd->fresh) {
  ------------------
  |  Branch (1349:16): [True: 357, False: 264k]
  ------------------
 1350|    357|        sd->fresh = FALSE;
  ------------------
  |  |   44|    357|#define FALSE 0
  ------------------
 1351|       |
 1352|    889|        do {
 1353|    889|            sd->firstcode = sd->oldcode =
 1354|    889|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|    889|#define FALSE 0
  ------------------
 1355|    889|        } while (sd->firstcode == sd->clear_code);
  ------------------
  |  Branch (1355:18): [True: 532, False: 357]
  ------------------
 1356|       |
 1357|    357|        return sd->firstcode;
 1358|    357|    }
 1359|       |
 1360|   264k|    if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1360:9): [True: 155k, False: 109k]
  ------------------
 1361|   155k|        return *--sd->sp;
 1362|   155k|    }
 1363|       |
 1364|   109k|    while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
  ------------------
  |  |   44|   109k|#define FALSE 0
  ------------------
  |  Branch (1364:12): [True: 108k, False: 549]
  ------------------
 1365|   108k|        if (code == sd->clear_code) {
  ------------------
  |  Branch (1365:13): [True: 2.26k, False: 106k]
  ------------------
 1366|   885k|            for (i = 0; i < sd->clear_code; ++i) {
  ------------------
  |  Branch (1366:25): [True: 883k, False: 2.26k]
  ------------------
 1367|   883k|                sd->table[0][i] = 0;
 1368|   883k|                sd->table[1][i] = i;
 1369|   883k|            }
 1370|       |
 1371|  8.40M|            for (; i < (1 << MAX_LWZ_BITS); ++i) {
  ------------------
  |  |   50|  8.40M|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1371:20): [True: 8.40M, False: 2.26k]
  ------------------
 1372|  8.40M|                sd->table[0][i] = sd->table[1][i] = 0;
 1373|  8.40M|            }
 1374|       |
 1375|  2.26k|            sd->code_size = sd->set_code_size + 1;
 1376|  2.26k|            sd->max_code_size = 2 * sd->clear_code;
 1377|  2.26k|            sd->max_code = sd->clear_code + 2;
 1378|  2.26k|            sd->sp = sd->stack;
 1379|  2.26k|            sd->firstcode = sd->oldcode =
 1380|  2.26k|                GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
  ------------------
  |  |   44|  2.26k|#define FALSE 0
  ------------------
 1381|       |
 1382|  2.26k|            return sd->firstcode;
 1383|   106k|        } else if (code == sd->end_code) {
  ------------------
  |  Branch (1383:20): [True: 327, False: 105k]
  ------------------
 1384|    327|            int count;
 1385|    327|            unsigned char buf[260];
 1386|       |
 1387|    327|            if (*ZeroDataBlockP) {
  ------------------
  |  Branch (1387:17): [True: 5, False: 322]
  ------------------
 1388|      5|                return -2;
 1389|      5|            }
 1390|       |
 1391|  1.00k|            while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
  ------------------
  |  Branch (1391:20): [True: 681, False: 322]
  ------------------
 1392|    681|                ;
 1393|       |
 1394|    322|            if (count != 0) {
  ------------------
  |  Branch (1394:17): [True: 45, False: 277]
  ------------------
 1395|     45|                return -2;
 1396|     45|            }
 1397|    322|        }
 1398|       |
 1399|   106k|        incode = code;
 1400|       |
 1401|   106k|        if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   106k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   106k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1401:13): [True: 0, False: 106k]
  ------------------
 1402|       |            /* Bad compressed data stream */
 1403|      0|            return -1;
 1404|      0|        }
 1405|       |
 1406|   106k|        if (code >= sd->max_code) {
  ------------------
  |  Branch (1406:13): [True: 30.0k, False: 76.1k]
  ------------------
 1407|  30.0k|            *sd->sp++ = sd->firstcode;
 1408|  30.0k|            code = sd->oldcode;
 1409|  30.0k|        }
 1410|       |
 1411|   248k|        while (code >= sd->clear_code) {
  ------------------
  |  Branch (1411:16): [True: 141k, False: 106k]
  ------------------
 1412|   141k|            if (sd->sp == (sd->stack + STACK_SIZE)) {
  ------------------
  |  |   83|   141k|#define STACK_SIZE ((1 << (MAX_LWZ_BITS)) * 2)
  |  |  ------------------
  |  |  |  |   50|   141k|#define MAX_LWZ_BITS 12
  |  |  ------------------
  ------------------
  |  Branch (1412:17): [True: 2, False: 141k]
  ------------------
 1413|       |                /* Bad compressed data stream */
 1414|      2|                return -1;
 1415|      2|            }
 1416|   141k|            if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   141k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1416:17): [True: 5, False: 141k]
  ------------------
 1417|       |                /* Corrupted code */
 1418|      5|                return -1;
 1419|      5|            }
 1420|       |
 1421|   141k|            *sd->sp++ = sd->table[1][code];
 1422|       |
 1423|   141k|            if (code == sd->table[0][code]) {
  ------------------
  |  Branch (1423:17): [True: 16.3k, False: 125k]
  ------------------
 1424|       |                /* Oh well */
 1425|  16.3k|            }
 1426|       |
 1427|   141k|            code = sd->table[0][code];
 1428|   141k|        }
 1429|   106k|        if (code >= (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   106k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1429:13): [True: 0, False: 106k]
  ------------------
 1430|       |            /* Corrupted code */
 1431|      0|            return -1;
 1432|      0|        }
 1433|       |
 1434|   106k|        *sd->sp++ = sd->firstcode = sd->table[1][code];
 1435|       |
 1436|   106k|        if ((code = sd->max_code) < (1 << MAX_LWZ_BITS)) {
  ------------------
  |  |   50|   106k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1436:13): [True: 105k, False: 1.17k]
  ------------------
 1437|   105k|            sd->table[0][code] = sd->oldcode;
 1438|   105k|            sd->table[1][code] = sd->firstcode;
 1439|   105k|            ++sd->max_code;
 1440|       |
 1441|   105k|            if ((sd->max_code >= sd->max_code_size) && (sd->max_code_size < (1 << MAX_LWZ_BITS))) {
  ------------------
  |  |   50|  1.88k|#define MAX_LWZ_BITS 12
  ------------------
  |  Branch (1441:17): [True: 1.88k, False: 103k]
  |  Branch (1441:56): [True: 1.85k, False: 36]
  ------------------
 1442|  1.85k|                sd->max_code_size *= 2;
 1443|  1.85k|                ++sd->code_size;
 1444|  1.85k|            }
 1445|   105k|        }
 1446|       |
 1447|   106k|        sd->oldcode = incode;
 1448|       |
 1449|   106k|        if (sd->sp > sd->stack) {
  ------------------
  |  Branch (1449:13): [True: 106k, False: 0]
  ------------------
 1450|   106k|            return *--sd->sp;
 1451|   106k|        }
 1452|   106k|    }
 1453|       |
 1454|    549|    return code;
 1455|   109k|}
gd_gif_in.c:GetCode:
 1307|   112k|{
 1308|   112k|    int rv;
 1309|       |
 1310|   112k|    rv = GetCode_(fd, scd, code_size, flag, ZeroDataBlockP);
 1311|       |
 1312|   112k|    if (VERBOSE) {
  ------------------
  |  |   37|   112k|#define VERBOSE 0
  |  |  ------------------
  |  |  |  Branch (37:17): [Folded, False: 112k]
  |  |  ------------------
  ------------------
 1313|      0|        printf("[GetCode(,%d,%d) returning %d]\n", code_size, flag, rv);
 1314|      0|    }
 1315|       |
 1316|   112k|    return rv;
 1317|   112k|}
gd_gif_in.c:GetCode_:
 1247|   112k|{
 1248|   112k|    int i, j, ret;
 1249|   112k|    int count;
 1250|       |
 1251|   112k|    if (flag) {
  ------------------
  |  Branch (1251:9): [True: 357, False: 112k]
  ------------------
 1252|    357|        scd->curbit = 0;
 1253|    357|        scd->lastbit = 0;
 1254|    357|        scd->last_byte = 2;
 1255|    357|        scd->done = FALSE;
  ------------------
  |  |   44|    357|#define FALSE 0
  ------------------
 1256|    357|        return 0;
 1257|    357|    }
 1258|       |
 1259|   112k|    if ((scd->curbit + code_size) >= scd->lastbit) {
  ------------------
  |  Branch (1259:9): [True: 3.30k, False: 108k]
  ------------------
 1260|  3.30k|        if (scd->done) {
  ------------------
  |  Branch (1260:13): [True: 409, False: 2.89k]
  ------------------
 1261|    409|            if (scd->curbit >= scd->lastbit) {
  ------------------
  |  Branch (1261:17): [True: 247, False: 162]
  ------------------
 1262|       |                /* Oh well */
 1263|    247|            }
 1264|    409|            return -1;
 1265|    409|        }
 1266|       |
 1267|  2.89k|        scd->buf[0] = scd->buf[scd->last_byte - 2];
 1268|  2.89k|        scd->buf[1] = scd->buf[scd->last_byte - 1];
 1269|  2.89k|        scd->last_byte = 2;
 1270|  2.89k|        scd->curbit = (scd->curbit - scd->lastbit) + 16;
 1271|  2.89k|        scd->lastbit = 16;
 1272|       |
 1273|  3.24k|        do {
 1274|  3.24k|            if (scd->last_byte > (CSD_BUF_SIZE - 255)) {
  ------------------
  |  |   85|  3.24k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1274:17): [True: 0, False: 3.24k]
  ------------------
 1275|      0|                return -1;
 1276|      0|            }
 1277|       |
 1278|  3.24k|            if ((count = GetDataBlock(fd, &scd->buf[scd->last_byte], ZeroDataBlockP)) <= 0) {
  ------------------
  |  Branch (1278:17): [True: 329, False: 2.91k]
  ------------------
 1279|    329|                scd->done = TRUE;
  ------------------
  |  |   43|    329|#define TRUE 1
  ------------------
 1280|    329|                break;
 1281|    329|            }
 1282|       |
 1283|  2.91k|            scd->last_byte += count;
 1284|  2.91k|            scd->lastbit += count * 8;
 1285|  2.91k|        } while ((scd->curbit + code_size) > scd->lastbit);
  ------------------
  |  Branch (1285:18): [True: 347, False: 2.56k]
  ------------------
 1286|  2.89k|    }
 1287|       |
 1288|   111k|    if ((scd->curbit + code_size) > scd->lastbit) {
  ------------------
  |  Branch (1288:9): [True: 218, False: 111k]
  ------------------
 1289|    218|        return -1;
 1290|    218|    }
 1291|       |
 1292|   111k|    if ((scd->curbit + code_size - 1) >= (CSD_BUF_SIZE * 8)) {
  ------------------
  |  |   85|   111k|#define CSD_BUF_SIZE 280
  ------------------
  |  Branch (1292:9): [True: 0, False: 111k]
  ------------------
 1293|      0|        ret = -1;
 1294|   111k|    } else {
 1295|   111k|        ret = 0;
 1296|  1.33M|        for (i = scd->curbit, j = 0; j < code_size; ++i, ++j) {
  ------------------
  |  Branch (1296:38): [True: 1.22M, False: 111k]
  ------------------
 1297|  1.22M|            ret |= ((scd->buf[i / 8] & (1 << (i % 8))) != 0) << j;
 1298|  1.22M|        }
 1299|   111k|    }
 1300|       |
 1301|   111k|    scd->curbit += code_size;
 1302|       |
 1303|   111k|    return ret;
 1304|   111k|}

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

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

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

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

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

