LLVMFuzzerTestOneInput:
   30|    214|{
   31|    214|    if (Size < 5)
  ------------------
  |  Branch (31:9): [True: 4, False: 210]
  ------------------
   32|      4|    {
   33|      4|        return 0;
   34|      4|    }
   35|    210|    FuzzedDataProvider fdp(Data, Size);
   36|    210|    uint32_t width = 10;
   37|    210|    const uint32_t length = 40;
   38|    210|    const uint32_t rows_per_strip = 1;
   39|       |
   40|    210|    const char *filename = "test_packbits.tif";
   41|    210|    TIFF *tif1 = TIFFOpen(filename, "w");
   42|    210|    if (!tif1)
  ------------------
  |  Branch (42:9): [True: 0, False: 210]
  ------------------
   43|      0|    {
   44|      0|        fprintf(stderr, "Can't create test TIFF file %s.\n", filename);
   45|      0|        return 1;
   46|      0|    }
   47|       |
   48|    210|    switch (fdp.ConsumeIntegralInRange(0, 2))
  ------------------
  |  Branch (48:13): [True: 207, False: 3]
  ------------------
   49|    210|    {
   50|    175|        case 0:
  ------------------
  |  Branch (50:9): [True: 175, False: 35]
  ------------------
   51|    175|            if (!TIFFSetField(tif1, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS))
  ------------------
  |  |  181|    175|#define TIFFTAG_COMPRESSION 259       /* data compression technique */
  ------------------
                          if (!TIFFSetField(tif1, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS))
  ------------------
  |  |  195|    175|#define COMPRESSION_PACKBITS 32773    /* Macintosh RLE */
  ------------------
  |  Branch (51:17): [True: 0, False: 175]
  ------------------
   52|      0|            {
   53|      0|                fprintf(stderr, "Can't set Compression tag.\n");
   54|      0|                TIFFClose(tif1);
   55|      0|                return 0;
   56|      0|            }
   57|    175|            if (!TIFFSetField(tif1, TIFFTAG_IMAGEWIDTH, width))
  ------------------
  |  |  178|    175|#define TIFFTAG_IMAGEWIDTH 256        /* image width in pixels */
  ------------------
  |  Branch (57:17): [True: 0, False: 175]
  ------------------
   58|      0|            {
   59|      0|                fprintf(stderr, "Can't set ImageWidth tag.\n");
   60|      0|                TIFFClose(tif1);
   61|      0|                return 0;
   62|      0|            }
   63|    175|            if (!TIFFSetField(tif1, TIFFTAG_IMAGELENGTH, length))
  ------------------
  |  |  179|    175|#define TIFFTAG_IMAGELENGTH 257       /* image height in pixels */
  ------------------
  |  Branch (63:17): [True: 0, False: 175]
  ------------------
   64|      0|            {
   65|      0|                fprintf(stderr, "Can't set ImageLength tag.\n");
   66|      0|                TIFFClose(tif1);
   67|      0|                return 0;
   68|      0|            }
   69|    175|            if (!TIFFSetField(tif1, TIFFTAG_BITSPERSAMPLE, 8))
  ------------------
  |  |  180|    175|#define TIFFTAG_BITSPERSAMPLE 258     /* bits per channel (sample) */
  ------------------
  |  Branch (69:17): [True: 0, False: 175]
  ------------------
   70|      0|            {
   71|      0|                fprintf(stderr, "Can't set BitsPerSample tag.\n");
   72|      0|                TIFFClose(tif1);
   73|      0|                return 0;
   74|      0|            }
   75|    175|            if (!TIFFSetField(tif1, TIFFTAG_SAMPLESPERPIXEL, 1))
  ------------------
  |  |  257|    175|#define TIFFTAG_SAMPLESPERPIXEL 277        /* samples per pixel */
  ------------------
  |  Branch (75:17): [True: 0, False: 175]
  ------------------
   76|      0|            {
   77|      0|                fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
   78|      0|                TIFFClose(tif1);
   79|      0|                return 0;
   80|      0|            }
   81|    175|            if (!TIFFSetField(tif1, TIFFTAG_ROWSPERSTRIP, rows_per_strip))
  ------------------
  |  |  258|    175|#define TIFFTAG_ROWSPERSTRIP 278           /* rows per strip of data */
  ------------------
  |  Branch (81:17): [True: 0, False: 175]
  ------------------
   82|      0|            {
   83|      0|                fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
   84|      0|                TIFFClose(tif1);
   85|      0|                return 0;
   86|      0|            }
   87|    175|            if (!TIFFSetField(tif1, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
  ------------------
  |  |  264|    175|#define TIFFTAG_PLANARCONFIG 284           /* storage organization */
  ------------------
                          if (!TIFFSetField(tif1, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
  ------------------
  |  |  265|    175|#define PLANARCONFIG_CONTIG 1              /* single image plane */
  ------------------
  |  Branch (87:17): [True: 0, False: 175]
  ------------------
   88|      0|            {
   89|      0|                fprintf(stderr, "Can't set PlanarConfiguration tag.\n");
   90|      0|                TIFFClose(tif1);
   91|      0|                return 0;
   92|      0|            }
   93|    207|        case 1:
  ------------------
  |  Branch (93:9): [True: 32, False: 178]
  ------------------
   94|    207|            if (!TIFFSetField(tif1, TIFFTAG_COMPRESSION, COMPRESSION_NONE))
  ------------------
  |  |  181|    207|#define TIFFTAG_COMPRESSION 259       /* data compression technique */
  ------------------
                          if (!TIFFSetField(tif1, TIFFTAG_COMPRESSION, COMPRESSION_NONE))
  ------------------
  |  |  182|    207|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
  |  Branch (94:17): [True: 0, False: 207]
  ------------------
   95|      0|            {
   96|      0|                fprintf(stderr, "Can't set Compression tag.\n");
   97|      0|                TIFFClose(tif1);
   98|      0|                return 0;
   99|      0|            }
  100|    207|            if (!TIFFSetField(tif1, TIFFTAG_IMAGEWIDTH, width))
  ------------------
  |  |  178|    207|#define TIFFTAG_IMAGEWIDTH 256        /* image width in pixels */
  ------------------
  |  Branch (100:17): [True: 0, False: 207]
  ------------------
  101|      0|            {
  102|      0|                fprintf(stderr, "Can't set ImageWidth tag.\n");
  103|      0|                TIFFClose(tif1);
  104|      0|                return 0;
  105|      0|            }
  106|    207|            if (!TIFFSetField(tif1, TIFFTAG_IMAGELENGTH, length))
  ------------------
  |  |  179|    207|#define TIFFTAG_IMAGELENGTH 257       /* image height in pixels */
  ------------------
  |  Branch (106:17): [True: 0, False: 207]
  ------------------
  107|      0|            {
  108|      0|                fprintf(stderr, "Can't set ImageWidth tag.\n");
  109|      0|                TIFFClose(tif1);
  110|      0|                return 0;
  111|      0|            }
  112|    207|            TIFFSetField(tif1, TIFFTAG_BITSPERSAMPLE, 8);
  ------------------
  |  |  180|    207|#define TIFFTAG_BITSPERSAMPLE 258     /* bits per channel (sample) */
  ------------------
  113|    207|            TIFFSetField(tif1, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  ------------------
  |  |  220|    207|#define TIFFTAG_PHOTOMETRIC 262            /* photometric interpretation */
  ------------------
                          TIFFSetField(tif1, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  ------------------
  |  |  222|    207|#define PHOTOMETRIC_MINISBLACK 1           /* min value is black */
  ------------------
  114|    207|            TIFFSetField(tif1, TIFFTAG_SAMPLESPERPIXEL, 1);
  ------------------
  |  |  257|    207|#define TIFFTAG_SAMPLESPERPIXEL 277        /* samples per pixel */
  ------------------
  115|    207|            TIFFSetField(tif1, TIFFTAG_ROWSPERSTRIP, 1);
  ------------------
  |  |  258|    207|#define TIFFTAG_ROWSPERSTRIP 278           /* rows per strip of data */
  ------------------
  116|    210|    }
  117|       |
  118|    210|    tsize_t stripsize = TIFFStripSize(tif1);
  119|    210|    tstrip_t stripcount = TIFFNumberOfStrips(tif1);
  120|    210|    std::vector<uint8_t> rBytes = fdp.ConsumeRemainingBytes<uint8_t>();
  121|       |
  122|    210|    TIFFWriteEncodedStrip(tif1, tstrip_t(0), static_cast<void *>(rBytes.data()),
  123|    210|                          static_cast<int>(rBytes.size()));
  124|    210|    TIFFClose(tif1);
  125|       |
  126|    210|    return 0;
  127|    210|}

_TIFFMultiply64:
   43|  2.79k|{
   44|  2.79k|    if (second && first > UINT64_MAX / second)
  ------------------
  |  Branch (44:9): [True: 2.79k, False: 3]
  |  Branch (44:19): [True: 0, False: 2.79k]
  ------------------
   45|      0|    {
   46|      0|        TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
   47|      0|        return 0;
   48|      0|    }
   49|       |
   50|  2.79k|    return first * second;
   51|  2.79k|}
_TIFFMultiplySSize:
   88|  1.85k|{
   89|  1.85k|    if (first <= 0 || second <= 0)
  ------------------
  |  Branch (89:9): [True: 0, False: 1.85k]
  |  Branch (89:23): [True: 0, False: 1.85k]
  ------------------
   90|      0|    {
   91|      0|        if (tif != NULL && where != NULL)
  ------------------
  |  Branch (91:13): [True: 0, False: 0]
  |  Branch (91:28): [True: 0, False: 0]
  ------------------
   92|      0|        {
   93|      0|            TIFFErrorExtR(tif, where,
   94|      0|                          "Invalid argument to _TIFFMultiplySSize() in %s",
   95|      0|                          where);
   96|      0|        }
   97|      0|        return 0;
   98|      0|    }
   99|       |
  100|  1.85k|    if (first > TIFF_TMSIZE_T_MAX / second)
  ------------------
  |  |   68|  1.85k|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
  |  Branch (100:9): [True: 0, False: 1.85k]
  ------------------
  101|      0|    {
  102|      0|        if (tif != NULL && where != NULL)
  ------------------
  |  Branch (102:13): [True: 0, False: 0]
  |  Branch (102:28): [True: 0, False: 0]
  ------------------
  103|      0|        {
  104|      0|            TIFFErrorExtR(tif, where, "Integer overflow in %s", where);
  105|      0|        }
  106|      0|        return 0;
  107|      0|    }
  108|  1.85k|    return first * second;
  109|  1.85k|}
_TIFFCastUInt64ToSSize:
  136|    624|{
  137|    624|    if (val > (uint64_t)TIFF_TMSIZE_T_MAX)
  ------------------
  |  |   68|    624|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
  |  Branch (137:9): [True: 0, False: 624]
  ------------------
  138|      0|    {
  139|      0|        if (tif != NULL && module != NULL)
  ------------------
  |  Branch (139:13): [True: 0, False: 0]
  |  Branch (139:28): [True: 0, False: 0]
  ------------------
  140|      0|        {
  141|      0|            TIFFErrorExtR(tif, module, "Integer overflow");
  142|      0|        }
  143|      0|        return 0;
  144|      0|    }
  145|    624|    return (tmsize_t)val;
  146|    624|}
_TIFFCheckRealloc:
  246|  1.85k|{
  247|  1.85k|    void *cp = NULL;
  248|  1.85k|    tmsize_t count = _TIFFMultiplySSize(tif, nmemb, elem_size, NULL);
  249|       |    /*
  250|       |     * Check for integer overflow.
  251|       |     */
  252|  1.85k|    if (count != 0)
  ------------------
  |  Branch (252:9): [True: 1.85k, False: 0]
  ------------------
  253|  1.85k|    {
  254|  1.85k|        cp = _TIFFreallocExt(tif, buffer, count);
  255|  1.85k|    }
  256|       |
  257|  1.85k|    if (cp == NULL)
  ------------------
  |  Branch (257:9): [True: 0, False: 1.85k]
  ------------------
  258|      0|    {
  259|      0|        TIFFErrorExtR(tif, tif->tif_name,
  260|      0|                      "Failed to allocate memory for %s "
  261|      0|                      "(%" TIFF_SSIZE_FORMAT " elements of %" TIFF_SSIZE_FORMAT
  262|      0|                      " bytes each)",
  263|      0|                      what, nmemb, elem_size);
  264|      0|    }
  265|       |
  266|  1.85k|    return cp;
  267|  1.85k|}
_TIFFCheckMalloc:
  271|  1.85k|{
  272|       |    return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what);
  273|  1.85k|}
_TIFFSeekOK:
  577|    510|{
  578|       |    /* Huge offsets, especially -1 / UINT64_MAX, can cause issues */
  579|       |    /* See http://bugzilla.maptools.org/show_bug.cgi?id=2726 */
  580|    510|    return off <= (~(uint64_t)0) / 2 && TIFFSeekFile(tif, off, SEEK_SET) == off;
  ------------------
  |  |  291|    510|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  |  Branch (580:12): [True: 510, False: 0]
  |  Branch (580:41): [True: 510, False: 0]
  ------------------
  581|    510|}

TIFFCleanup:
   45|    210|{
   46|       |    /*
   47|       |     * Flush buffered data and directory (if dirty).
   48|       |     */
   49|    210|    if (tif->tif_mode != O_RDONLY)
  ------------------
  |  Branch (49:9): [True: 210, False: 0]
  ------------------
   50|    210|        TIFFFlush(tif);
   51|    210|    TIFFFreeDirectory(tif);
   52|       |
   53|    210|    _TIFFCleanupIFDOffsetAndNumberMaps(tif);
   54|       |
   55|       |    /*
   56|       |     * Clean up client info links.
   57|       |     */
   58|    210|    while (tif->tif_clientinfo)
  ------------------
  |  Branch (58:12): [True: 0, False: 210]
  ------------------
   59|      0|    {
   60|      0|        TIFFClientInfoLink *psLink = tif->tif_clientinfo;
   61|       |
   62|      0|        tif->tif_clientinfo = psLink->next;
   63|      0|        _TIFFfreeExt(tif, psLink->name);
   64|      0|        _TIFFfreeExt(tif, psLink);
   65|      0|    }
   66|       |
   67|    210|    if (tif->tif_rawdata && (tif->tif_flags & TIFF_MYBUFFER))
  ------------------
  |  |  131|      0|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  |  Branch (67:9): [True: 0, False: 210]
  |  Branch (67:29): [True: 0, False: 0]
  ------------------
   68|      0|    {
   69|      0|        _TIFFfreeExt(tif, tif->tif_rawdata);
   70|      0|        tif->tif_rawdata = NULL;
   71|      0|        tif->tif_rawdatasize = 0;
   72|      0|    }
   73|    210|    if (isMapped(tif))
  ------------------
  |  |  283|    210|#define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
  |  |  ------------------
  |  |  |  |  133|    210|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  |  |  ------------------
  |  |  |  Branch (283:23): [True: 0, False: 210]
  |  |  ------------------
  ------------------
   74|      0|        TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);
  ------------------
  |  |  297|      0|    ((*(tif)->tif_unmapproc)((tif)->tif_clientdata, (addr), (size)))
  ------------------
   75|       |
   76|       |    /*
   77|       |     * Clean up custom fields.
   78|       |     */
   79|    210|    if (tif->tif_fields && tif->tif_nfields > 0)
  ------------------
  |  Branch (79:9): [True: 210, False: 0]
  |  Branch (79:28): [True: 210, False: 0]
  ------------------
   80|    210|    {
   81|    210|        uint32_t i;
   82|       |
   83|  32.3k|        for (i = 0; i < tif->tif_nfields; i++)
  ------------------
  |  Branch (83:21): [True: 32.1k, False: 210]
  ------------------
   84|  32.1k|        {
   85|  32.1k|            TIFFField *fld = tif->tif_fields[i];
   86|  32.1k|            if (fld->field_name != NULL)
  ------------------
  |  Branch (86:17): [True: 32.1k, False: 0]
  ------------------
   87|  32.1k|            {
   88|  32.1k|                if (fld->field_bit == FIELD_CUSTOM &&
  ------------------
  |  |  394|  64.2k|#define FIELD_CUSTOM 65
  ------------------
  |  Branch (88:21): [True: 21.6k, False: 10.5k]
  ------------------
   89|       |                    /* caution: tif_fields[i] must not be the beginning of a
   90|       |                     * fields-array. Otherwise the following tags are also freed
   91|       |                     * with the first free().
   92|       |                     */
   93|  21.6k|                    TIFFFieldIsAnonymous(fld))
  ------------------
  |  Branch (93:21): [True: 0, False: 21.6k]
  ------------------
   94|      0|                {
   95|      0|                    _TIFFfreeExt(tif, (void *)fld->field_name);
   96|      0|                    _TIFFfreeExt(tif, fld);
   97|      0|                }
   98|  32.1k|            }
   99|  32.1k|        }
  100|       |
  101|    210|        _TIFFfreeExt(tif, tif->tif_fields);
  102|    210|    }
  103|       |
  104|    210|    if (tif->tif_nfieldscompat > 0)
  ------------------
  |  Branch (104:9): [True: 0, False: 210]
  ------------------
  105|      0|    {
  106|      0|        uint32_t i;
  107|       |
  108|      0|        for (i = 0; i < tif->tif_nfieldscompat; i++)
  ------------------
  |  Branch (108:21): [True: 0, False: 0]
  ------------------
  109|      0|        {
  110|      0|            if (tif->tif_fieldscompat[i].allocated_size)
  ------------------
  |  Branch (110:17): [True: 0, False: 0]
  ------------------
  111|      0|                _TIFFfreeExt(tif, tif->tif_fieldscompat[i].fields);
  112|      0|        }
  113|      0|        _TIFFfreeExt(tif, tif->tif_fieldscompat);
  114|      0|    }
  115|       |
  116|    210|    if (tif->tif_cur_cumulated_mem_alloc != 0)
  ------------------
  |  Branch (116:9): [True: 0, False: 210]
  ------------------
  117|      0|    {
  118|      0|        TIFFErrorExtR(tif, "TIFFCleanup",
  119|      0|                      "tif_cur_cumulated_mem_alloc = %" PRIu64 " whereas it "
  120|      0|                      "should be 0",
  121|      0|                      (uint64_t)tif->tif_cur_cumulated_mem_alloc);
  122|      0|    }
  123|       |
  124|       |    _TIFFfreeExt(NULL, tif);
  125|    210|}
_TIFFCleanupIFDOffsetAndNumberMaps:
  132|    210|{
  133|    210|    if (tif->tif_map_dir_offset_to_number)
  ------------------
  |  Branch (133:9): [True: 170, False: 40]
  ------------------
  134|    170|    {
  135|    170|        TIFFHashSetDestroy(tif->tif_map_dir_offset_to_number);
  136|    170|        tif->tif_map_dir_offset_to_number = NULL;
  137|    170|    }
  138|    210|    if (tif->tif_map_dir_number_to_offset)
  ------------------
  |  Branch (138:9): [True: 170, False: 40]
  ------------------
  139|    170|    {
  140|    170|        TIFFHashSetDestroy(tif->tif_map_dir_number_to_offset);
  141|       |        tif->tif_map_dir_number_to_offset = NULL;
  142|    170|    }
  143|    210|}
TIFFClose:
  160|    210|{
  161|    210|    if (tif != NULL)
  ------------------
  |  Branch (161:9): [True: 210, False: 0]
  ------------------
  162|    210|    {
  163|    210|        TIFFCloseProc closeproc = tif->tif_closeproc;
  164|    210|        thandle_t fd = tif->tif_clientdata;
  165|       |
  166|    210|        TIFFCleanup(tif);
  167|    210|        (void)(*closeproc)(fd);
  168|    210|    }
  169|    210|}

_TIFFSetDefaultCompressionState:
  155|    940|{
  156|    940|    tif->tif_fixuptags = _TIFFNoFixupTags;
  157|    940|    tif->tif_decodestatus = TRUE;
  ------------------
  |  |   74|    940|#define TRUE 1
  ------------------
  158|    940|    tif->tif_setupdecode = _TIFFtrue;
  159|    940|    tif->tif_predecode = _TIFFNoPreCode;
  160|    940|    tif->tif_decoderow = _TIFFNoRowDecode;
  161|    940|    tif->tif_decodestrip = _TIFFNoStripDecode;
  162|    940|    tif->tif_decodetile = _TIFFNoTileDecode;
  163|    940|    tif->tif_encodestatus = TRUE;
  ------------------
  |  |   74|    940|#define TRUE 1
  ------------------
  164|    940|    tif->tif_setupencode = _TIFFtrue;
  165|    940|    tif->tif_preencode = _TIFFNoPreCode;
  166|    940|    tif->tif_postencode = _TIFFtrue;
  167|    940|    tif->tif_encoderow = _TIFFNoRowEncode;
  168|    940|    tif->tif_encodestrip = _TIFFNoStripEncode;
  169|    940|    tif->tif_encodetile = _TIFFNoTileEncode;
  170|    940|    tif->tif_close = _TIFFvoid;
  171|    940|    tif->tif_seek = _TIFFNoSeek;
  172|    940|    tif->tif_cleanup = _TIFFvoid;
  173|    940|    tif->tif_defstripsize = _TIFFDefaultStripSize;
  174|    940|    tif->tif_deftilesize = _TIFFDefaultTileSize;
  175|    940|    tif->tif_getmaxcompressionratio = _TIFFDefaultGetMaxCompressionRatio;
  176|    940|    tif->tif_flags &= ~(TIFF_NOBITREV | TIFF_NOREADRAW | TIFF_UPSAMPLED);
  ------------------
  |  |  130|    940|#define TIFF_NOBITREV 0x00100U    /* inhibit bit reversal logic */
  ------------------
                  tif->tif_flags &= ~(TIFF_NOBITREV | TIFF_NOREADRAW | TIFF_UPSAMPLED);
  ------------------
  |  |  141|    940|    0x20000U /* skip reading of raw uncompressed image data */
  ------------------
                  tif->tif_flags &= ~(TIFF_NOBITREV | TIFF_NOREADRAW | TIFF_UPSAMPLED);
  ------------------
  |  |  136|    940|#define TIFF_UPSAMPLED 0x04000U   /* library is doing data up-sampling */
  ------------------
  177|    940|}
TIFFSetCompressionScheme:
  180|    730|{
  181|    730|    const TIFFCodec *c = TIFFFindCODEC((uint16_t)scheme);
  182|       |
  183|    730|    _TIFFSetDefaultCompressionState(tif);
  184|    730|    if (scheme == COMPRESSION_NONE)
  ------------------
  |  |  182|    730|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
  |  Branch (184:9): [True: 555, False: 175]
  ------------------
  185|    555|        tif->tif_getmaxcompressionratio = _TIFFGetMaxCompressionRatioOne;
  186|       |    /*
  187|       |     * Don't treat an unknown compression scheme as an error.
  188|       |     * This permits applications to open files with data that
  189|       |     * the library does not have builtin support for, but which
  190|       |     * may still be meaningful.
  191|       |     */
  192|    730|    return (c ? (*c->init)(tif, scheme) : 1);
  ------------------
  |  Branch (192:13): [True: 730, False: 0]
  ------------------
  193|    730|}
TIFFFindCODEC:
  215|    730|{
  216|    730|    const TIFFCodec *c;
  217|    730|    codec_t *cd;
  218|       |
  219|    730|    for (cd = registeredCODECS; cd; cd = cd->next)
  ------------------
  |  Branch (219:33): [True: 0, False: 730]
  ------------------
  220|      0|        if (cd->info->scheme == scheme)
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  221|      0|            return ((const TIFFCodec *)cd->info);
  222|  1.08k|    for (c = _TIFFBuiltinCODECS; c->name; c++)
  ------------------
  |  Branch (222:34): [True: 1.08k, False: 0]
  ------------------
  223|  1.08k|        if (c->scheme == scheme)
  ------------------
  |  Branch (223:13): [True: 730, False: 350]
  ------------------
  224|    730|            return (c);
  225|      0|    return NULL;
  226|    730|}
tif_compress.c:_TIFFtrue:
  136|    207|{
  137|    207|    (void)tif;
  138|    207|    return (1);
  139|    207|}
tif_compress.c:_TIFFvoid:
  140|  1.10k|static void _TIFFvoid(TIFF *tif) { (void)tif; }

TIFFSetField:
 1413|  3.05k|{
 1414|  3.05k|    va_list ap;
 1415|  3.05k|    int status;
 1416|       |
 1417|  3.05k|    va_start(ap, tag);
 1418|  3.05k|    status = TIFFVSetField(tif, tag, ap);
 1419|       |    va_end(ap);
 1420|  3.05k|    return (status);
 1421|  3.05k|}
TIFFVSetField:
 1472|  3.05k|{
 1473|  3.05k|    return OkToChangeTag(tif, tag)
  ------------------
  |  Branch (1473:12): [True: 3.05k, False: 0]
  ------------------
 1474|  3.05k|               ? (*tif->tif_tagmethods.vsetfield)(tif, tag, ap)
 1475|  3.05k|               : 0;
 1476|  3.05k|}
_TIFFResetTifDirAndInitStrileCounters:
 1896|    590|{
 1897|    590|    _TIFFmemset(td, 0, sizeof(*td));
 1898|    590|    td->td_curstrip = NOSTRIP;      /* invalid strip = NOSTRIP */
  ------------------
  |  |  123|    590|#define NOSTRIP ((uint32_t)(-1)) /* undefined state */
  ------------------
 1899|    590|    td->td_row = (uint32_t)-1;      /* read/write pre-increment */
 1900|    590|    td->td_col = (uint32_t)-1;      /* read/write pre-increment */
 1901|    590|    td->td_scanlinesize = 0;        /* initialize to zero */
 1902|    590|    td->td_curtile = NOTILE;        /* invalid tile = NOTILE */
  ------------------
  |  |  128|    590|#define NOTILE ((uint32_t)(-1)) /* undefined state */
  ------------------
 1903|    590|    td->td_tilesize = (tmsize_t)-1; /* invalidate tilezize */
 1904|    590|}
TIFFFreeDirectory:
 1910|    550|{
 1911|    550|    TIFFDirectory *td = &tif->tif_dir;
 1912|    550|    int i;
 1913|       |
 1914|    550|    (*tif->tif_cleanup)(tif);
 1915|    550|    _TIFFmemset(td->td_fieldsset, 0, sizeof(td->td_fieldsset));
 1916|    550|    CleanupField(td_sminsamplevalue);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1917|    550|    CleanupField(td_smaxsamplevalue);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1918|    550|    CleanupField(td_colormap[0]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1919|    550|    CleanupField(td_colormap[1]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1920|    550|    CleanupField(td_colormap[2]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1921|    550|    td->td_colormap_count = 0;
 1922|    550|    CleanupField(td_sampleinfo);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1923|    550|    CleanupField(td_subifd);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1924|    550|    CleanupField(td_inknames);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1925|    550|    CleanupField(td_refblackwhite);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1926|    550|    CleanupField(td_transferfunction[0]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1927|    550|    CleanupField(td_transferfunction[1]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1928|    550|    CleanupField(td_transferfunction[2]);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1929|    550|    td->td_transferfunction_count = 0;
 1930|    550|    CleanupField(td_stripoffset_p);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 207, False: 343]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|    207|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|    207|            td->member = 0;                                                    \
  |  | 1888|    207|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1931|    550|    CleanupField(td_stripbytecount_p);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 207, False: 343]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|    207|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|    207|            td->member = 0;                                                    \
  |  | 1888|    207|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1932|    550|    td->td_stripoffsetbyteallocsize = 0;
 1933|    550|    TIFFClrFieldBit(tif, FIELD_YCBCRSUBSAMPLING);
  ------------------
  |  |  269|    550|#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  266|    550|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  265|    550|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
 1934|    550|    TIFFClrFieldBit(tif, FIELD_YCBCRPOSITIONING);
  ------------------
  |  |  269|    550|#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  266|    550|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  265|    550|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
 1935|       |
 1936|       |    /* Cleanup custom tag values */
 1937|    550|    for (i = 0; i < td->td_customValueCount; i++)
  ------------------
  |  Branch (1937:17): [True: 0, False: 550]
  ------------------
 1938|      0|    {
 1939|      0|        if (td->td_customValues[i].value)
  ------------------
  |  Branch (1939:13): [True: 0, False: 0]
  ------------------
 1940|      0|            _TIFFfreeExt(tif, td->td_customValues[i].value);
 1941|      0|    }
 1942|       |
 1943|    550|    td->td_customValueCount = 0;
 1944|    550|    CleanupField(td_customValues);
  ------------------
  |  | 1883|    550|    {                                                                          \
  |  | 1884|    550|        if (td->member)                                                        \
  |  |  ------------------
  |  |  |  Branch (1884:13): [True: 0, False: 550]
  |  |  ------------------
  |  | 1885|    550|        {                                                                      \
  |  | 1886|      0|            _TIFFfreeExt(tif, td->member);                                     \
  |  | 1887|      0|            td->member = 0;                                                    \
  |  | 1888|      0|        }                                                                      \
  |  | 1889|    550|    }
  ------------------
 1945|       |
 1946|    550|    _TIFFmemset(&(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
 1947|    550|    _TIFFmemset(&(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
 1948|       |
 1949|       |    /* Reset some internal parameters for IFD data size checking. */
 1950|    550|    tif->tif_dir.td_dirdatasize_read = 0;
 1951|    550|    tif->tif_dir.td_dirdatasize_write = 0;
 1952|    550|    if (tif->tif_dir.td_dirdatasize_offsets != NULL)
  ------------------
  |  Branch (1952:9): [True: 0, False: 550]
  ------------------
 1953|      0|    {
 1954|      0|        _TIFFfreeExt(tif, tif->tif_dir.td_dirdatasize_offsets);
 1955|      0|        tif->tif_dir.td_dirdatasize_offsets = NULL;
 1956|      0|        tif->tif_dir.td_dirdatasize_Noffsets = 0;
 1957|      0|    }
 1958|    550|    tif->tif_dir.td_iswrittentofile = FALSE;
  ------------------
  |  |   75|    550|#define FALSE 0
  ------------------
 1959|       |    /* Note: tif->tif_dir structure is set to zero in TIFFDefaultDirectory() */
 1960|    550|}
TIFFCreateDirectory:
 1983|    170|{
 1984|       |    /* Free previously allocated memory and setup default values. */
 1985|    170|    TIFFFreeDirectory(tif);
 1986|    170|    TIFFDefaultDirectory(tif);
 1987|    170|    tif->tif_diroff = 0;
 1988|    170|    tif->tif_nextdiroff = 0;
 1989|    170|    tif->tif_curoff = 0;
 1990|    170|    tif->tif_dir.td_iswrittentofile = FALSE;
  ------------------
  |  |   75|    170|#define FALSE 0
  ------------------
 1991|    170|    return 0;
 1992|    170|}
TIFFDefaultDirectory:
 2053|    380|{
 2054|    380|    TIFFDirectory *td = &tif->tif_dir;
 2055|    380|    const TIFFFieldArray *tiffFieldArray;
 2056|       |
 2057|    380|    tiffFieldArray = _TIFFGetFields();
 2058|    380|    _TIFFSetupFields(tif, tiffFieldArray);
 2059|       |    /* Reset tif->tif_dir structure to zero and
 2060|       |     * initialize some IFD strile counter and index parameters. */
 2061|    380|    _TIFFResetTifDirAndInitStrileCounters(td);
 2062|    380|    td->td_fillorder = FILLORDER_MSB2LSB;
  ------------------
  |  |  241|    380|#define FILLORDER_MSB2LSB 1                /* most significant -> least */
  ------------------
 2063|    380|    td->td_bitspersample = 1;
 2064|    380|    td->td_threshholding = THRESHHOLD_BILEVEL;
  ------------------
  |  |  235|    380|#define THRESHHOLD_BILEVEL 1               /* b&w art scan */
  ------------------
 2065|    380|    td->td_orientation = ORIENTATION_TOPLEFT;
  ------------------
  |  |  249|    380|#define ORIENTATION_TOPLEFT 1              /* row 0 top, col 0 lhs */
  ------------------
 2066|    380|    td->td_samplesperpixel = 1;
 2067|    380|    td->td_rowsperstrip = (uint32_t)-1;
 2068|    380|    td->td_tilewidth = 0;
 2069|    380|    td->td_tilelength = 0;
 2070|    380|    td->td_tiledepth = 1;
 2071|       |#ifdef STRIPBYTECOUNTSORTED_UNUSED
 2072|       |    td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */
 2073|       |#endif
 2074|    380|    td->td_resolutionunit = RESUNIT_INCH;
  ------------------
  |  |  289|    380|#define RESUNIT_INCH 2                     /* english */
  ------------------
 2075|    380|    td->td_sampleformat = SAMPLEFORMAT_UINT;
  ------------------
  |  |  334|    380|#define SAMPLEFORMAT_UINT 1                /* !unsigned integer data */
  ------------------
 2076|    380|    td->td_imagedepth = 1;
 2077|    380|    td->td_ycbcrsubsampling[0] = 2;
 2078|    380|    td->td_ycbcrsubsampling[1] = 2;
 2079|    380|    td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED;
  ------------------
  |  |  390|    380|#define YCBCRPOSITION_CENTERED 1           /* !as in PostScript Level 2 */
  ------------------
 2080|    380|    tif->tif_postdecode = _TIFFNoPostDecode;
 2081|    380|    tif->tif_foundfield = NULL;
 2082|    380|    tif->tif_tagmethods.vsetfield = _TIFFVSetField;
 2083|    380|    tif->tif_tagmethods.vgetfield = _TIFFVGetField;
 2084|    380|    tif->tif_tagmethods.printdir = NULL;
 2085|       |    /* additional default values */
 2086|    380|    td->td_planarconfig = PLANARCONFIG_CONTIG;
  ------------------
  |  |  265|    380|#define PLANARCONFIG_CONTIG 1              /* single image plane */
  ------------------
 2087|    380|    td->td_compression = COMPRESSION_NONE;
  ------------------
  |  |  182|    380|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
 2088|    380|    td->td_subfiletype = 0;
 2089|    380|    td->td_minsamplevalue = 0;
 2090|       |    /* td_bitspersample=1 is always set in TIFFDefaultDirectory().
 2091|       |     * Therefore, td_maxsamplevalue has to be re-calculated in
 2092|       |     * TIFFGetFieldDefaulted(). */
 2093|    380|    td->td_maxsamplevalue = 1; /* Default for td_bitspersample=1 */
 2094|    380|    td->td_extrasamples = 0;
 2095|    380|    td->td_sampleinfo = NULL;
 2096|       |
 2097|       |    /*
 2098|       |     *  Give client code a chance to install their own
 2099|       |     *  tag extensions & methods, prior to compression overloads,
 2100|       |     *  but do some prior cleanup first.
 2101|       |     * (http://trac.osgeo.org/gdal/ticket/5054)
 2102|       |     */
 2103|    380|    if (tif->tif_nfieldscompat > 0)
  ------------------
  |  Branch (2103:9): [True: 0, False: 380]
  ------------------
 2104|      0|    {
 2105|      0|        uint32_t i;
 2106|       |
 2107|      0|        for (i = 0; i < tif->tif_nfieldscompat; i++)
  ------------------
  |  Branch (2107:21): [True: 0, False: 0]
  ------------------
 2108|      0|        {
 2109|      0|            if (tif->tif_fieldscompat[i].allocated_size)
  ------------------
  |  Branch (2109:17): [True: 0, False: 0]
  ------------------
 2110|      0|                _TIFFfreeExt(tif, tif->tif_fieldscompat[i].fields);
 2111|      0|        }
 2112|      0|        _TIFFfreeExt(tif, tif->tif_fieldscompat);
 2113|      0|        tif->tif_nfieldscompat = 0;
 2114|      0|        tif->tif_fieldscompat = NULL;
 2115|      0|    }
 2116|    380|    if (_TIFFextender)
  ------------------
  |  Branch (2116:9): [True: 0, False: 380]
  ------------------
 2117|      0|        (*_TIFFextender)(tif);
 2118|    380|    (void)TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  ------------------
  |  |  181|    380|#define TIFFTAG_COMPRESSION 259       /* data compression technique */
  ------------------
                  (void)TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  ------------------
  |  |  182|    380|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
 2119|       |    /*
 2120|       |     * NB: The directory is marked dirty as a result of setting
 2121|       |     * up the default compression scheme.  However, this really
 2122|       |     * isn't correct -- we want TIFF_DIRTYDIRECT to be set only
 2123|       |     * if the user does something.  We could just do the setup
 2124|       |     * by hand, but it seems better to use the normal mechanism
 2125|       |     * (i.e. TIFFSetField).
 2126|       |     */
 2127|    380|    tif->tif_flags &= ~TIFF_DIRTYDIRECT;
  ------------------
  |  |  125|    380|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
 2128|       |
 2129|       |    /*
 2130|       |     * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
 2131|       |     * we clear the ISTILED flag when setting up a new directory.
 2132|       |     * Should we also be clearing stuff like INSUBIFD?
 2133|       |     */
 2134|    380|    tif->tif_flags &= ~TIFF_ISTILED;
  ------------------
  |  |  132|    380|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  ------------------
 2135|       |
 2136|    380|    return (1);
 2137|    380|}
tif_dir.c:OkToChangeTag:
 1380|  3.05k|{
 1381|  3.05k|    const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
  ------------------
  |  |  389|  3.05k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
 1382|  3.05k|    if (!fip)
  ------------------
  |  Branch (1382:9): [True: 0, False: 3.05k]
  ------------------
 1383|      0|    { /* unknown tag */
 1384|      0|        TIFFErrorExtR(tif, "TIFFSetField", "%s: Unknown %stag %" PRIu32,
 1385|      0|                      tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag);
  ------------------
  |  |  280|      0|#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  |  |  ------------------
  |  |  |  Branch (280:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1386|      0|        return (0);
 1387|      0|    }
 1388|  3.05k|    if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) &&
  ------------------
  |  |  179|  6.10k|#define TIFFTAG_IMAGELENGTH 257       /* image height in pixels */
  ------------------
                  if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) &&
  ------------------
  |  |  128|  2.67k|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
  |  Branch (1388:9): [True: 2.67k, False: 382]
  |  Branch (1388:39): [True: 0, False: 2.67k]
  ------------------
 1389|      0|        !fip->field_oktochange)
  ------------------
  |  Branch (1389:9): [True: 0, False: 0]
  ------------------
 1390|      0|    {
 1391|       |        /*
 1392|       |         * Consult info table to see if tag can be changed
 1393|       |         * after we've started writing.  We only allow changes
 1394|       |         * to those tags that don't/shouldn't affect the
 1395|       |         * compression and/or format of the data.
 1396|       |         */
 1397|      0|        TIFFErrorExtR(tif, "TIFFSetField",
 1398|      0|                      "%s: Cannot modify tag \"%s\" while writing",
 1399|      0|                      tif->tif_name, fip->field_name);
 1400|      0|        return (0);
 1401|      0|    }
 1402|  3.05k|    return (1);
 1403|  3.05k|}
tif_dir.c:_TIFFVSetField:
  410|  3.05k|{
  411|  3.05k|    static const char module[] = "_TIFFVSetField";
  412|       |
  413|  3.05k|    TIFFDirectory *td = &tif->tif_dir;
  414|  3.05k|    int status = 1;
  415|  3.05k|    uint32_t v32, v;
  416|  3.05k|    double dblval;
  417|  3.05k|    char *s;
  418|  3.05k|    void *old_custom_value = NULL;
  419|  3.05k|    const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
  ------------------
  |  |  389|  3.05k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
  420|  3.05k|    uint32_t standard_tag = tag;
  421|  3.05k|    if (fip == NULL) /* cannot happen since OkToChangeTag() already checks it */
  ------------------
  |  Branch (421:9): [True: 0, False: 3.05k]
  ------------------
  422|      0|        return 0;
  423|       |    /*
  424|       |     * We want to force the custom code to be used for custom
  425|       |     * fields even if the tag happens to match a well known
  426|       |     * one - important for reinterpreted handling of standard
  427|       |     * tag values in custom directories (i.e. EXIF)
  428|       |     */
  429|  3.05k|    if (fip->field_bit == FIELD_CUSTOM)
  ------------------
  |  |  394|  3.05k|#define FIELD_CUSTOM 65
  ------------------
  |  Branch (429:9): [True: 0, False: 3.05k]
  ------------------
  430|      0|    {
  431|      0|        standard_tag = 0;
  432|      0|    }
  433|       |
  434|  3.05k|    switch (standard_tag)
  435|  3.05k|    {
  436|      0|        case TIFFTAG_SUBFILETYPE:
  ------------------
  |  |  170|      0|#define TIFFTAG_SUBFILETYPE 254       /* subfile data descriptor */
  ------------------
  |  Branch (436:9): [True: 0, False: 3.05k]
  ------------------
  437|      0|            td->td_subfiletype = (uint32_t)va_arg(ap, uint32_t);
  438|      0|            break;
  439|    382|        case TIFFTAG_IMAGEWIDTH:
  ------------------
  |  |  178|    382|#define TIFFTAG_IMAGEWIDTH 256        /* image width in pixels */
  ------------------
  |  Branch (439:9): [True: 382, False: 2.67k]
  ------------------
  440|    382|            td->td_imagewidth = (uint32_t)va_arg(ap, uint32_t);
  441|    382|            break;
  442|    382|        case TIFFTAG_IMAGELENGTH:
  ------------------
  |  |  179|    382|#define TIFFTAG_IMAGELENGTH 257       /* image height in pixels */
  ------------------
  |  Branch (442:9): [True: 382, False: 2.67k]
  ------------------
  443|    382|            td->td_imagelength = (uint32_t)va_arg(ap, uint32_t);
  444|    382|            break;
  445|    382|        case TIFFTAG_BITSPERSAMPLE:
  ------------------
  |  |  180|    382|#define TIFFTAG_BITSPERSAMPLE 258     /* bits per channel (sample) */
  ------------------
  |  Branch (445:9): [True: 382, False: 2.67k]
  ------------------
  446|    382|            v = (uint16_t)va_arg(ap, uint16_vap);
  447|       |            /*
  448|       |             * ColorMap and TransferFunction were allocated with
  449|       |             * 2**BitsPerSample entries per plane, for the BitsPerSample in
  450|       |             * effect when they were set.  A different BitsPerSample leaves
  451|       |             * them the wrong length for the tag they describe, so cancel
  452|       |             * them, as SamplesPerPixel already does for SMinSampleValue and
  453|       |             * SMaxSampleValue (see
  454|       |             * http://bugzilla.maptools.org/show_bug.cgi?id=2500), and as
  455|       |             * SamplesPerPixel and ExtraSamples already do for the number of
  456|       |             * TransferFunction curves (see
  457|       |             * http://bugzilla.maptools.org/show_bug.cgi?id=2820).
  458|       |             *
  459|       |             * Only a tag the caller actually set is cancelled: the default
  460|       |             * TransferFunction built by TIFFGetFieldDefaulted() does not set
  461|       |             * FIELD_TRANSFERFUNCTION and is not the caller's to lose.
  462|       |             */
  463|    382|            if (v != td->td_bitspersample)
  ------------------
  |  Branch (463:17): [True: 207, False: 175]
  ------------------
  464|    207|            {
  465|    207|                if (TIFFFieldSet(tif, FIELD_COLORMAP))
  ------------------
  |  |  267|    207|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  466|      0|                {
  467|       |                    /*
  468|       |                     * A narrower BitsPerSample needs fewer entries than are
  469|       |                     * already allocated, so the planes still describe the
  470|       |                     * directory and only the recorded length has to follow.
  471|       |                     * Discarding them would write a Palette image with no
  472|       |                     * ColorMap, which cannot be read back.
  473|       |                     */
  474|      0|                    uint64_t newcount =
  475|      0|                        v < 32 ? (uint64_t)1 << v : (uint64_t)0;
  ------------------
  |  Branch (475:25): [True: 0, False: 0]
  ------------------
  476|       |
  477|      0|                    if (newcount != 0 && newcount <= td->td_colormap_count)
  ------------------
  |  Branch (477:25): [True: 0, False: 0]
  |  Branch (477:42): [True: 0, False: 0]
  ------------------
  478|      0|                        td->td_colormap_count = (uint32_t)newcount;
  479|      0|                    else
  480|      0|                    {
  481|      0|                        TIFFWarningExtR(tif, module,
  482|      0|                                        "BitsPerSample tag value is changing, "
  483|      0|                                        "but ColorMap was read with a "
  484|      0|                                        "different value. Canceling it");
  485|      0|                        cancelColorMap(tif);
  486|      0|                    }
  487|      0|                }
  488|    207|                if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION))
  ------------------
  |  |  267|    207|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  489|      0|                {
  490|      0|                    TIFFWarningExtR(tif, module,
  491|      0|                                    "BitsPerSample tag value is changing, "
  492|      0|                                    "but TransferFunction was read with a "
  493|      0|                                    "different value. Canceling it");
  494|      0|                    cancelTransferFunction(tif);
  495|      0|                }
  496|    207|            }
  497|    382|            td->td_bitspersample = (uint16_t)v;
  498|       |            /*
  499|       |             * If the data require post-decoding processing to byte-swap
  500|       |             * samples, set it up here.  Note that since tags are required
  501|       |             * to be ordered, compression code can override this behavior
  502|       |             * in the setup method if it wants to roll the post decoding
  503|       |             * work in with its normal work.
  504|       |             */
  505|    382|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    382|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (505:17): [True: 0, False: 382]
  ------------------
  506|      0|            {
  507|      0|                if (td->td_bitspersample == 8)
  ------------------
  |  Branch (507:21): [True: 0, False: 0]
  ------------------
  508|      0|                    tif->tif_postdecode = _TIFFNoPostDecode;
  509|      0|                else if (td->td_bitspersample == 16)
  ------------------
  |  Branch (509:26): [True: 0, False: 0]
  ------------------
  510|      0|                    tif->tif_postdecode = _TIFFSwab16BitData;
  511|      0|                else if (td->td_bitspersample == 24)
  ------------------
  |  Branch (511:26): [True: 0, False: 0]
  ------------------
  512|      0|                    tif->tif_postdecode = _TIFFSwab24BitData;
  513|      0|                else if (td->td_bitspersample == 32)
  ------------------
  |  Branch (513:26): [True: 0, False: 0]
  ------------------
  514|      0|                    tif->tif_postdecode = _TIFFSwab32BitData;
  515|      0|                else if (td->td_bitspersample == 64)
  ------------------
  |  Branch (515:26): [True: 0, False: 0]
  ------------------
  516|      0|                    tif->tif_postdecode = _TIFFSwab64BitData;
  517|      0|                else if (td->td_bitspersample == 128) /* two 64's */
  ------------------
  |  Branch (517:26): [True: 0, False: 0]
  ------------------
  518|      0|                    tif->tif_postdecode = _TIFFSwab64BitData;
  519|      0|            }
  520|    382|            break;
  521|    762|        case TIFFTAG_COMPRESSION:
  ------------------
  |  |  181|    762|#define TIFFTAG_COMPRESSION 259       /* data compression technique */
  ------------------
  |  Branch (521:9): [True: 762, False: 2.29k]
  ------------------
  522|    762|            v = (uint16_t)va_arg(ap, uint16_vap);
  523|       |            /*
  524|       |             * If we're changing the compression scheme, notify the
  525|       |             * previous module so that it can cleanup any state it's
  526|       |             * setup.
  527|       |             */
  528|    762|            if (TIFFFieldSet(tif, FIELD_COMPRESSION))
  ------------------
  |  |  267|    762|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    762|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    762|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 382, False: 380]
  |  |  ------------------
  ------------------
  529|    382|            {
  530|    382|                if ((uint32_t)td->td_compression == v)
  ------------------
  |  Branch (530:21): [True: 32, False: 350]
  ------------------
  531|     32|                    break;
  532|    350|                (*tif->tif_cleanup)(tif);
  533|    350|                tif->tif_flags &= ~TIFF_CODERSETUP;
  ------------------
  |  |  127|    350|#define TIFF_CODERSETUP 0x00020U  /* encoder/decoder setup done */
  ------------------
  534|    350|            }
  535|       |            /*
  536|       |             * Setup new compression routine state.
  537|       |             */
  538|    730|            if ((status = TIFFSetCompressionScheme(tif, (int)v)) != 0)
  ------------------
  |  Branch (538:17): [True: 730, False: 0]
  ------------------
  539|    730|                td->td_compression = (uint16_t)v;
  540|      0|            else
  541|      0|                status = 0;
  542|    730|            break;
  543|    207|        case TIFFTAG_PHOTOMETRIC:
  ------------------
  |  |  220|    207|#define TIFFTAG_PHOTOMETRIC 262            /* photometric interpretation */
  ------------------
  |  Branch (543:9): [True: 207, False: 2.84k]
  ------------------
  544|    207|            td->td_photometric = (uint16_t)va_arg(ap, uint16_vap);
  545|    207|            break;
  546|      0|        case TIFFTAG_THRESHHOLDING:
  ------------------
  |  |  234|      0|#define TIFFTAG_THRESHHOLDING 263          /* +thresholding used on data */
  ------------------
  |  Branch (546:9): [True: 0, False: 3.05k]
  ------------------
  547|      0|            td->td_threshholding = (uint16_t)va_arg(ap, uint16_vap);
  548|      0|            break;
  549|      0|        case TIFFTAG_FILLORDER:
  ------------------
  |  |  240|      0|#define TIFFTAG_FILLORDER 266              /* data order within a byte */
  ------------------
  |  Branch (549:9): [True: 0, False: 3.05k]
  ------------------
  550|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  551|      0|            if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)
  ------------------
  |  |  242|      0|#define FILLORDER_LSB2MSB 2                /* least significant -> most */
  ------------------
                          if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)
  ------------------
  |  |  241|      0|#define FILLORDER_MSB2LSB 1                /* most significant -> least */
  ------------------
  |  Branch (551:17): [True: 0, False: 0]
  |  Branch (551:43): [True: 0, False: 0]
  ------------------
  552|      0|                goto badvalue;
  553|      0|            td->td_fillorder = (uint16_t)v;
  554|      0|            break;
  555|      0|        case TIFFTAG_ORIENTATION:
  ------------------
  |  |  248|      0|#define TIFFTAG_ORIENTATION 274            /* +image orientation */
  ------------------
  |  Branch (555:9): [True: 0, False: 3.05k]
  ------------------
  556|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  557|      0|            if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v)
  ------------------
  |  |  249|      0|#define ORIENTATION_TOPLEFT 1              /* row 0 top, col 0 lhs */
  ------------------
                          if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v)
  ------------------
  |  |  256|      0|#define ORIENTATION_LEFTBOT 8              /* row 0 lhs, col 0 bottom */
  ------------------
  |  Branch (557:17): [True: 0, False: 0]
  |  Branch (557:44): [True: 0, False: 0]
  ------------------
  558|      0|                goto badvalue;
  559|      0|            else
  560|      0|                td->td_orientation = (uint16_t)v;
  561|      0|            break;
  562|    382|        case TIFFTAG_SAMPLESPERPIXEL:
  ------------------
  |  |  257|    382|#define TIFFTAG_SAMPLESPERPIXEL 277        /* samples per pixel */
  ------------------
  |  Branch (562:9): [True: 382, False: 2.67k]
  ------------------
  563|    382|            v = (uint16_t)va_arg(ap, uint16_vap);
  564|    382|            if (v == 0)
  ------------------
  |  Branch (564:17): [True: 0, False: 382]
  ------------------
  565|      0|                goto badvalue;
  566|    382|            if (v != td->td_samplesperpixel)
  ------------------
  |  Branch (566:17): [True: 0, False: 382]
  ------------------
  567|      0|            {
  568|       |                /* See http://bugzilla.maptools.org/show_bug.cgi?id=2500 */
  569|      0|                if (td->td_sminsamplevalue != NULL)
  ------------------
  |  Branch (569:21): [True: 0, False: 0]
  ------------------
  570|      0|                {
  571|      0|                    TIFFWarningExtR(tif, module,
  572|      0|                                    "SamplesPerPixel tag value is changing, "
  573|      0|                                    "but SMinSampleValue tag was read with a "
  574|      0|                                    "different value. Canceling it");
  575|      0|                    TIFFClrFieldBit(tif, FIELD_SMINSAMPLEVALUE);
  ------------------
  |  |  269|      0|#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  576|      0|                    _TIFFfreeExt(tif, td->td_sminsamplevalue);
  577|      0|                    td->td_sminsamplevalue = NULL;
  578|      0|                }
  579|      0|                if (td->td_smaxsamplevalue != NULL)
  ------------------
  |  Branch (579:21): [True: 0, False: 0]
  ------------------
  580|      0|                {
  581|      0|                    TIFFWarningExtR(tif, module,
  582|      0|                                    "SamplesPerPixel tag value is changing, "
  583|      0|                                    "but SMaxSampleValue tag was read with a "
  584|      0|                                    "different value. Canceling it");
  585|      0|                    TIFFClrFieldBit(tif, FIELD_SMAXSAMPLEVALUE);
  ------------------
  |  |  269|      0|#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  586|      0|                    _TIFFfreeExt(tif, td->td_smaxsamplevalue);
  587|      0|                    td->td_smaxsamplevalue = NULL;
  588|      0|                }
  589|       |                /* Test if 3 transfer functions instead of just one are now
  590|       |                   needed See http://bugzilla.maptools.org/show_bug.cgi?id=2820
  591|       |                 */
  592|      0|                if (td->td_transferfunction[0] != NULL &&
  ------------------
  |  Branch (592:21): [True: 0, False: 0]
  ------------------
  593|      0|                    (v - td->td_extrasamples > 1) &&
  ------------------
  |  Branch (593:21): [True: 0, False: 0]
  ------------------
  594|      0|                    !(td->td_samplesperpixel - td->td_extrasamples > 1))
  ------------------
  |  Branch (594:21): [True: 0, False: 0]
  ------------------
  595|      0|                {
  596|      0|                    TIFFWarningExtR(tif, module,
  597|      0|                                    "SamplesPerPixel tag value is changing, "
  598|      0|                                    "but TransferFunction was read with a "
  599|      0|                                    "different value. Canceling it");
  600|      0|                    cancelTransferFunction(tif);
  601|      0|                }
  602|      0|            }
  603|    382|            td->td_samplesperpixel = (uint16_t)v;
  604|    382|            break;
  605|    382|        case TIFFTAG_ROWSPERSTRIP:
  ------------------
  |  |  258|    382|#define TIFFTAG_ROWSPERSTRIP 278           /* rows per strip of data */
  ------------------
  |  Branch (605:9): [True: 382, False: 2.67k]
  ------------------
  606|    382|            v32 = (uint32_t)va_arg(ap, uint32_t);
  607|    382|            if (v32 == 0)
  ------------------
  |  Branch (607:17): [True: 0, False: 382]
  ------------------
  608|      0|                goto badvalue32;
  609|    382|            td->td_rowsperstrip = v32;
  610|    382|            if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS))
  ------------------
  |  |  267|    382|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    382|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    382|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  |  Branch (610:17): [True: 382, False: 0]
  ------------------
  611|    382|            {
  612|    382|                td->td_tilelength = v32;
  613|    382|                td->td_tilewidth = td->td_imagewidth;
  614|    382|            }
  615|    382|            break;
  616|      0|        case TIFFTAG_MINSAMPLEVALUE:
  ------------------
  |  |  260|      0|#define TIFFTAG_MINSAMPLEVALUE 280         /* +minimum sample value */
  ------------------
  |  Branch (616:9): [True: 0, False: 3.05k]
  ------------------
  617|      0|            td->td_minsamplevalue = (uint16_t)va_arg(ap, uint16_vap);
  618|      0|            break;
  619|      0|        case TIFFTAG_MAXSAMPLEVALUE:
  ------------------
  |  |  261|      0|#define TIFFTAG_MAXSAMPLEVALUE 281         /* +maximum sample value */
  ------------------
  |  Branch (619:9): [True: 0, False: 3.05k]
  ------------------
  620|      0|            td->td_maxsamplevalue = (uint16_t)va_arg(ap, uint16_vap);
  621|      0|            break;
  622|      0|        case TIFFTAG_SMINSAMPLEVALUE:
  ------------------
  |  |  340|      0|#define TIFFTAG_SMINSAMPLEVALUE 340        /* !variable MinSampleValue */
  ------------------
  |  Branch (622:9): [True: 0, False: 3.05k]
  ------------------
  623|      0|            if (tif->tif_flags & TIFF_PERSAMPLE)
  ------------------
  |  |  146|      0|#define TIFF_PERSAMPLE 0x400000U  /* get/set per sample tags as arrays */
  ------------------
  |  Branch (623:17): [True: 0, False: 0]
  ------------------
  624|      0|                _TIFFsetDoubleArrayExt(tif, &td->td_sminsamplevalue,
  625|      0|                                       va_arg(ap, double *),
  626|      0|                                       td->td_samplesperpixel);
  627|      0|            else
  628|      0|                setDoubleArrayOneValue(tif, &td->td_sminsamplevalue,
  629|      0|                                       va_arg(ap, double),
  630|      0|                                       td->td_samplesperpixel);
  631|      0|            break;
  632|      0|        case TIFFTAG_SMAXSAMPLEVALUE:
  ------------------
  |  |  341|      0|#define TIFFTAG_SMAXSAMPLEVALUE 341        /* !variable MaxSampleValue */
  ------------------
  |  Branch (632:9): [True: 0, False: 3.05k]
  ------------------
  633|      0|            if (tif->tif_flags & TIFF_PERSAMPLE)
  ------------------
  |  |  146|      0|#define TIFF_PERSAMPLE 0x400000U  /* get/set per sample tags as arrays */
  ------------------
  |  Branch (633:17): [True: 0, False: 0]
  ------------------
  634|      0|                _TIFFsetDoubleArrayExt(tif, &td->td_smaxsamplevalue,
  635|      0|                                       va_arg(ap, double *),
  636|      0|                                       td->td_samplesperpixel);
  637|      0|            else
  638|      0|                setDoubleArrayOneValue(tif, &td->td_smaxsamplevalue,
  639|      0|                                       va_arg(ap, double),
  640|      0|                                       td->td_samplesperpixel);
  641|      0|            break;
  642|      0|        case TIFFTAG_XRESOLUTION:
  ------------------
  |  |  262|      0|#define TIFFTAG_XRESOLUTION 282            /* pixels/resolution in x */
  ------------------
  |  Branch (642:9): [True: 0, False: 3.05k]
  ------------------
  643|      0|            dblval = va_arg(ap, double);
  644|      0|            if (isnan(dblval) || dblval < 0)
  ------------------
  |  Branch (644:17): [True: 0, False: 0]
  |  Branch (644:34): [True: 0, False: 0]
  ------------------
  645|      0|                goto badvaluedouble;
  646|      0|            td->td_xresolution = _TIFFClampDoubleToFloat(dblval);
  647|      0|            break;
  648|      0|        case TIFFTAG_YRESOLUTION:
  ------------------
  |  |  263|      0|#define TIFFTAG_YRESOLUTION 283            /* pixels/resolution in y */
  ------------------
  |  Branch (648:9): [True: 0, False: 3.05k]
  ------------------
  649|      0|            dblval = va_arg(ap, double);
  650|      0|            if (isnan(dblval) || dblval < 0)
  ------------------
  |  Branch (650:17): [True: 0, False: 0]
  |  Branch (650:34): [True: 0, False: 0]
  ------------------
  651|      0|                goto badvaluedouble;
  652|      0|            td->td_yresolution = _TIFFClampDoubleToFloat(dblval);
  653|      0|            break;
  654|    175|        case TIFFTAG_PLANARCONFIG:
  ------------------
  |  |  264|    175|#define TIFFTAG_PLANARCONFIG 284           /* storage organization */
  ------------------
  |  Branch (654:9): [True: 175, False: 2.87k]
  ------------------
  655|    175|            v = (uint16_t)va_arg(ap, uint16_vap);
  656|    175|            if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE)
  ------------------
  |  |  265|    350|#define PLANARCONFIG_CONTIG 1              /* single image plane */
  ------------------
                          if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE)
  ------------------
  |  |  266|      0|#define PLANARCONFIG_SEPARATE 2            /* separate planes of data */
  ------------------
  |  Branch (656:17): [True: 0, False: 175]
  |  Branch (656:45): [True: 0, False: 0]
  ------------------
  657|      0|                goto badvalue;
  658|    175|            td->td_planarconfig = (uint16_t)v;
  659|    175|            break;
  660|      0|        case TIFFTAG_XPOSITION:
  ------------------
  |  |  268|      0|#define TIFFTAG_XPOSITION 286              /* x page offset of image lhs */
  ------------------
  |  Branch (660:9): [True: 0, False: 3.05k]
  ------------------
  661|      0|            td->td_xposition = _TIFFClampDoubleToFloat(va_arg(ap, double));
  662|      0|            break;
  663|      0|        case TIFFTAG_YPOSITION:
  ------------------
  |  |  269|      0|#define TIFFTAG_YPOSITION 287              /* y page offset of image lhs */
  ------------------
  |  Branch (663:9): [True: 0, False: 3.05k]
  ------------------
  664|      0|            td->td_yposition = _TIFFClampDoubleToFloat(va_arg(ap, double));
  665|      0|            break;
  666|      0|        case TIFFTAG_RESOLUTIONUNIT:
  ------------------
  |  |  287|      0|#define TIFFTAG_RESOLUTIONUNIT 296         /* units of resolutions */
  ------------------
  |  Branch (666:9): [True: 0, False: 3.05k]
  ------------------
  667|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  668|      0|            if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)
  ------------------
  |  |  288|      0|#define RESUNIT_NONE 1                     /* no meaningful units */
  ------------------
                          if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)
  ------------------
  |  |  290|      0|#define RESUNIT_CENTIMETER 3               /* metric */
  ------------------
  |  Branch (668:17): [True: 0, False: 0]
  |  Branch (668:37): [True: 0, False: 0]
  ------------------
  669|      0|                goto badvalue;
  670|      0|            td->td_resolutionunit = (uint16_t)v;
  671|      0|            break;
  672|      0|        case TIFFTAG_PAGENUMBER:
  ------------------
  |  |  291|      0|#define TIFFTAG_PAGENUMBER 297             /* page numbers of multi-page */
  ------------------
  |  Branch (672:9): [True: 0, False: 3.05k]
  ------------------
  673|      0|            td->td_pagenumber[0] = (uint16_t)va_arg(ap, uint16_vap);
  674|      0|            td->td_pagenumber[1] = (uint16_t)va_arg(ap, uint16_vap);
  675|      0|            break;
  676|      0|        case TIFFTAG_HALFTONEHINTS:
  ------------------
  |  |  310|      0|#define TIFFTAG_HALFTONEHINTS 321          /* !highlight+shadow info */
  ------------------
  |  Branch (676:9): [True: 0, False: 3.05k]
  ------------------
  677|      0|            td->td_halftonehints[0] = (uint16_t)va_arg(ap, uint16_vap);
  678|      0|            td->td_halftonehints[1] = (uint16_t)va_arg(ap, uint16_vap);
  679|      0|            break;
  680|      0|        case TIFFTAG_COLORMAP:
  ------------------
  |  |  309|      0|#define TIFFTAG_COLORMAP 320               /* RGB map for palette image */
  ------------------
  |  Branch (680:9): [True: 0, False: 3.05k]
  ------------------
  681|      0|            if (td->td_bitspersample >= 32)
  ------------------
  |  Branch (681:17): [True: 0, False: 0]
  ------------------
  682|      0|            {
  683|      0|                v = td->td_bitspersample;
  684|      0|                goto badvalue;
  685|      0|            }
  686|      0|            v32 = 1U << td->td_bitspersample;
  687|      0|            if (!setColorMap(tif, ap, v32))
  ------------------
  |  Branch (687:17): [True: 0, False: 0]
  ------------------
  688|      0|                status = 0;
  689|      0|            break;
  690|      0|        case TIFFTAG_EXTRASAMPLES:
  ------------------
  |  |  329|      0|#define TIFFTAG_EXTRASAMPLES 338           /* !info about extra samples */
  ------------------
  |  Branch (690:9): [True: 0, False: 3.05k]
  ------------------
  691|      0|            if (!setExtraSamples(tif, ap, &v))
  ------------------
  |  Branch (691:17): [True: 0, False: 0]
  ------------------
  692|      0|                goto badvalue;
  693|      0|            break;
  694|      0|        case TIFFTAG_MATTEING:
  ------------------
  |  |  405|      0|#define TIFFTAG_MATTEING 32995   /* $use ExtraSamples */
  ------------------
  |  Branch (694:9): [True: 0, False: 3.05k]
  ------------------
  695|      0|            td->td_extrasamples = (((uint16_t)va_arg(ap, uint16_vap)) != 0);
  696|      0|            if (td->td_extrasamples)
  ------------------
  |  Branch (696:17): [True: 0, False: 0]
  ------------------
  697|      0|            {
  698|      0|                uint16_t sv = EXTRASAMPLE_ASSOCALPHA;
  ------------------
  |  |  331|      0|#define EXTRASAMPLE_ASSOCALPHA 1           /* !associated alpha data */
  ------------------
  699|      0|                _TIFFsetShortArrayExt(tif, &td->td_sampleinfo, &sv, 1);
  700|      0|            }
  701|      0|            break;
  702|      0|        case TIFFTAG_TILEWIDTH:
  ------------------
  |  |  311|      0|#define TIFFTAG_TILEWIDTH 322              /* !tile width in pixels */
  ------------------
  |  Branch (702:9): [True: 0, False: 3.05k]
  ------------------
  703|      0|            v32 = (uint32_t)va_arg(ap, uint32_t);
  704|      0|            if (v32 % 16)
  ------------------
  |  Branch (704:17): [True: 0, False: 0]
  ------------------
  705|      0|            {
  706|      0|                if (tif->tif_mode != O_RDONLY)
  ------------------
  |  Branch (706:21): [True: 0, False: 0]
  ------------------
  707|      0|                    goto badvalue32;
  708|      0|                TIFFWarningExtR(
  709|      0|                    tif, tif->tif_name,
  710|      0|                    "Nonstandard tile width %" PRIu32 ", convert file", v32);
  711|      0|            }
  712|      0|            td->td_tilewidth = v32;
  713|      0|            tif->tif_flags |= TIFF_ISTILED;
  ------------------
  |  |  132|      0|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  ------------------
  714|      0|            break;
  715|      0|        case TIFFTAG_TILELENGTH:
  ------------------
  |  |  312|      0|#define TIFFTAG_TILELENGTH 323             /* !tile height in pixels */
  ------------------
  |  Branch (715:9): [True: 0, False: 3.05k]
  ------------------
  716|      0|            v32 = (uint32_t)va_arg(ap, uint32_t);
  717|      0|            if (v32 % 16)
  ------------------
  |  Branch (717:17): [True: 0, False: 0]
  ------------------
  718|      0|            {
  719|      0|                if (tif->tif_mode != O_RDONLY)
  ------------------
  |  Branch (719:21): [True: 0, False: 0]
  ------------------
  720|      0|                    goto badvalue32;
  721|      0|                TIFFWarningExtR(
  722|      0|                    tif, tif->tif_name,
  723|      0|                    "Nonstandard tile length %" PRIu32 ", convert file", v32);
  724|      0|            }
  725|      0|            td->td_tilelength = v32;
  726|      0|            tif->tif_flags |= TIFF_ISTILED;
  ------------------
  |  |  132|      0|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  ------------------
  727|      0|            break;
  728|      0|        case TIFFTAG_TILEDEPTH:
  ------------------
  |  |  408|      0|#define TIFFTAG_TILEDEPTH 32998  /* z depth/data tile */
  ------------------
  |  Branch (728:9): [True: 0, False: 3.05k]
  ------------------
  729|      0|            v32 = (uint32_t)va_arg(ap, uint32_t);
  730|      0|            if (v32 == 0)
  ------------------
  |  Branch (730:17): [True: 0, False: 0]
  ------------------
  731|      0|                goto badvalue32;
  732|      0|            td->td_tiledepth = v32;
  733|      0|            break;
  734|      0|        case TIFFTAG_DATATYPE:
  ------------------
  |  |  406|      0|#define TIFFTAG_DATATYPE 32996   /* $use SampleFormat */
  ------------------
  |  Branch (734:9): [True: 0, False: 3.05k]
  ------------------
  735|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  736|      0|            switch (v)
  737|      0|            {
  738|      0|                case DATATYPE_VOID:
  ------------------
  |  |   39|      0|#define DATATYPE_VOID 0   /* !untyped data */
  ------------------
  |  Branch (738:17): [True: 0, False: 0]
  ------------------
  739|      0|                    v = SAMPLEFORMAT_VOID;
  ------------------
  |  |  337|      0|#define SAMPLEFORMAT_VOID 4                /* !untyped data */
  ------------------
  740|      0|                    break;
  741|      0|                case DATATYPE_INT:
  ------------------
  |  |   40|      0|#define DATATYPE_INT 1    /* !signed integer data */
  ------------------
  |  Branch (741:17): [True: 0, False: 0]
  ------------------
  742|      0|                    v = SAMPLEFORMAT_INT;
  ------------------
  |  |  335|      0|#define SAMPLEFORMAT_INT 2                 /* !signed integer data */
  ------------------
  743|      0|                    break;
  744|      0|                case DATATYPE_UINT:
  ------------------
  |  |   41|      0|#define DATATYPE_UINT 2   /* !unsigned integer data */
  ------------------
  |  Branch (744:17): [True: 0, False: 0]
  ------------------
  745|      0|                    v = SAMPLEFORMAT_UINT;
  ------------------
  |  |  334|      0|#define SAMPLEFORMAT_UINT 1                /* !unsigned integer data */
  ------------------
  746|      0|                    break;
  747|      0|                case DATATYPE_IEEEFP:
  ------------------
  |  |   42|      0|#define DATATYPE_IEEEFP 3 /* !IEEE floating point data */
  ------------------
  |  Branch (747:17): [True: 0, False: 0]
  ------------------
  748|      0|                    v = SAMPLEFORMAT_IEEEFP;
  ------------------
  |  |  336|      0|#define SAMPLEFORMAT_IEEEFP 3              /* !IEEE floating point data */
  ------------------
  749|      0|                    break;
  750|      0|                default:
  ------------------
  |  Branch (750:17): [True: 0, False: 0]
  ------------------
  751|      0|                    goto badvalue;
  752|      0|            }
  753|      0|            td->td_sampleformat = (uint16_t)v;
  754|      0|            break;
  755|      0|        case TIFFTAG_SAMPLEFORMAT:
  ------------------
  |  |  333|      0|#define TIFFTAG_SAMPLEFORMAT 339           /* !data sample format */
  ------------------
  |  Branch (755:9): [True: 0, False: 3.05k]
  ------------------
  756|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  757|      0|            if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)
  ------------------
  |  |  334|      0|#define SAMPLEFORMAT_UINT 1                /* !unsigned integer data */
  ------------------
                          if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)
  ------------------
  |  |  339|      0|#define SAMPLEFORMAT_COMPLEXIEEEFP 6       /* !complex ieee floating */
  ------------------
  |  Branch (757:17): [True: 0, False: 0]
  |  Branch (757:42): [True: 0, False: 0]
  ------------------
  758|      0|                goto badvalue;
  759|      0|            td->td_sampleformat = (uint16_t)v;
  760|       |
  761|       |            /*  Try to fix up the SWAB function for complex data. */
  762|      0|            if (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT &&
  ------------------
  |  |  338|      0|#define SAMPLEFORMAT_COMPLEXINT 5          /* !complex signed int */
  ------------------
  |  Branch (762:17): [True: 0, False: 0]
  ------------------
  763|      0|                td->td_bitspersample == 32 &&
  ------------------
  |  Branch (763:17): [True: 0, False: 0]
  ------------------
  764|      0|                tif->tif_postdecode == _TIFFSwab32BitData)
  ------------------
  |  Branch (764:17): [True: 0, False: 0]
  ------------------
  765|      0|                tif->tif_postdecode = _TIFFSwab16BitData;
  766|      0|            else if ((td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT ||
  ------------------
  |  |  338|      0|#define SAMPLEFORMAT_COMPLEXINT 5          /* !complex signed int */
  ------------------
  |  Branch (766:23): [True: 0, False: 0]
  ------------------
  767|      0|                      td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP) &&
  ------------------
  |  |  339|      0|#define SAMPLEFORMAT_COMPLEXIEEEFP 6       /* !complex ieee floating */
  ------------------
  |  Branch (767:23): [True: 0, False: 0]
  ------------------
  768|      0|                     td->td_bitspersample == 64 &&
  ------------------
  |  Branch (768:22): [True: 0, False: 0]
  ------------------
  769|      0|                     tif->tif_postdecode == _TIFFSwab64BitData)
  ------------------
  |  Branch (769:22): [True: 0, False: 0]
  ------------------
  770|      0|                tif->tif_postdecode = _TIFFSwab32BitData;
  771|      0|            break;
  772|      0|        case TIFFTAG_IMAGEDEPTH:
  ------------------
  |  |  407|      0|#define TIFFTAG_IMAGEDEPTH 32997 /* z depth of image */
  ------------------
  |  Branch (772:9): [True: 0, False: 3.05k]
  ------------------
  773|      0|            td->td_imagedepth = (uint32_t)va_arg(ap, uint32_t);
  774|      0|            break;
  775|      0|        case TIFFTAG_SUBIFD:
  ------------------
  |  |  321|      0|#define TIFFTAG_SUBIFD 330                 /* subimage descriptors */
  ------------------
  |  Branch (775:9): [True: 0, False: 3.05k]
  ------------------
  776|      0|            if ((tif->tif_flags & TIFF_INSUBIFD) == 0)
  ------------------
  |  |  135|      0|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (776:17): [True: 0, False: 0]
  ------------------
  777|      0|            {
  778|      0|                td->td_nsubifd = (uint16_t)va_arg(ap, uint16_vap);
  779|      0|                _TIFFsetLong8Array(tif, &td->td_subifd,
  780|      0|                                   (uint64_t *)va_arg(ap, uint64_t *),
  781|      0|                                   (uint32_t)td->td_nsubifd);
  782|      0|            }
  783|      0|            else
  784|      0|            {
  785|      0|                TIFFErrorExtR(tif, module, "%s: Sorry, cannot nest SubIFDs",
  786|      0|                              tif->tif_name);
  787|      0|                status = 0;
  788|      0|            }
  789|      0|            break;
  790|      0|        case TIFFTAG_YCBCRPOSITIONING:
  ------------------
  |  |  389|      0|#define TIFFTAG_YCBCRPOSITIONING 531       /* !subsample positioning */
  ------------------
  |  Branch (790:9): [True: 0, False: 3.05k]
  ------------------
  791|      0|            td->td_ycbcrpositioning = (uint16_t)va_arg(ap, uint16_vap);
  792|      0|            break;
  793|      0|        case TIFFTAG_YCBCRSUBSAMPLING:
  ------------------
  |  |  388|      0|#define TIFFTAG_YCBCRSUBSAMPLING 530       /* !YCbCr subsampling factors */
  ------------------
  |  Branch (793:9): [True: 0, False: 3.05k]
  ------------------
  794|      0|            td->td_ycbcrsubsampling[0] = (uint16_t)va_arg(ap, uint16_vap);
  795|      0|            td->td_ycbcrsubsampling[1] = (uint16_t)va_arg(ap, uint16_vap);
  796|      0|            break;
  797|      0|        case TIFFTAG_TRANSFERFUNCTION:
  ------------------
  |  |  298|      0|#define TIFFTAG_TRANSFERFUNCTION 301       /* !colorimetry info */
  ------------------
  |  Branch (797:9): [True: 0, False: 3.05k]
  ------------------
  798|      0|            if (td->td_bitspersample >= 32)
  ------------------
  |  Branch (798:17): [True: 0, False: 0]
  ------------------
  799|      0|            {
  800|      0|                v = td->td_bitspersample;
  801|      0|                goto badvalue;
  802|      0|            }
  803|      0|            if (!setTransferFunction(tif, ap, 1U << td->td_bitspersample))
  ------------------
  |  Branch (803:17): [True: 0, False: 0]
  ------------------
  804|      0|                status = 0;
  805|      0|            break;
  806|      0|        case TIFFTAG_REFERENCEBLACKWHITE:
  ------------------
  |  |  392|      0|#define TIFFTAG_REFERENCEBLACKWHITE 532    /* !colorimetry info */
  ------------------
  |  Branch (806:9): [True: 0, False: 3.05k]
  ------------------
  807|       |            /* XXX should check for null range */
  808|      0|            _TIFFsetFloatArrayExt(tif, &td->td_refblackwhite,
  809|      0|                                  va_arg(ap, float *), 6);
  810|      0|            break;
  811|      0|        case TIFFTAG_INKNAMES:
  ------------------
  |  |  325|      0|#define TIFFTAG_INKNAMES 333               /* !ascii names of inks */
  ------------------
  |  Branch (811:9): [True: 0, False: 3.05k]
  ------------------
  812|      0|        {
  813|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  814|      0|            s = va_arg(ap, char *);
  815|      0|            uint16_t ninksinstring;
  816|      0|            ninksinstring = countInkNamesString(tif, v, s);
  817|      0|            status = ninksinstring > 0;
  818|      0|            if (ninksinstring > 0)
  ------------------
  |  Branch (818:17): [True: 0, False: 0]
  ------------------
  819|      0|            {
  820|      0|                _TIFFsetNString(tif, &td->td_inknames, s, v);
  821|      0|                td->td_inknameslen = (int)v;
  822|       |                /* Set NumberOfInks to the value ninksinstring */
  823|      0|                if (TIFFFieldSet(tif, FIELD_NUMBEROFINKS))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  824|      0|                {
  825|      0|                    if (td->td_numberofinks != ninksinstring)
  ------------------
  |  Branch (825:25): [True: 0, False: 0]
  ------------------
  826|      0|                    {
  827|      0|                        TIFFErrorExtR(
  828|      0|                            tif, module,
  829|      0|                            "Warning %s; Tag %s:\n  Value %" PRIu16
  830|      0|                            " of NumberOfInks is different from the number of "
  831|      0|                            "inks %" PRIu16
  832|      0|                            ".\n  -> NumberOfInks value adapted to %" PRIu16 "",
  833|      0|                            tif->tif_name, fip->field_name, td->td_numberofinks,
  834|      0|                            ninksinstring, ninksinstring);
  835|      0|                        td->td_numberofinks = ninksinstring;
  836|      0|                    }
  837|      0|                }
  838|      0|                else
  839|      0|                {
  840|      0|                    td->td_numberofinks = ninksinstring;
  841|      0|                    TIFFSetFieldBit(tif, FIELD_NUMBEROFINKS);
  ------------------
  |  |  268|      0|#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  842|      0|                }
  843|      0|                if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  844|      0|                {
  845|      0|                    if (td->td_numberofinks != td->td_samplesperpixel)
  ------------------
  |  Branch (845:25): [True: 0, False: 0]
  ------------------
  846|      0|                    {
  847|      0|                        TIFFErrorExtR(tif, module,
  848|      0|                                      "Warning %s; Tag %s:\n  Value %" PRIu16
  849|      0|                                      " of NumberOfInks is different from the "
  850|      0|                                      "SamplesPerPixel value %" PRIu16 "",
  851|      0|                                      tif->tif_name, fip->field_name,
  852|      0|                                      td->td_numberofinks,
  853|      0|                                      td->td_samplesperpixel);
  854|      0|                    }
  855|      0|                }
  856|      0|            }
  857|      0|        }
  858|      0|        break;
  859|      0|        case TIFFTAG_NUMBEROFINKS:
  ------------------
  |  |  326|      0|#define TIFFTAG_NUMBEROFINKS 334           /* !number of inks */
  ------------------
  |  Branch (859:9): [True: 0, False: 3.05k]
  ------------------
  860|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  861|       |            /* If InkNames already set also NumberOfInks is set accordingly and
  862|       |             * should be equal */
  863|      0|            if (TIFFFieldSet(tif, FIELD_INKNAMES))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  864|      0|            {
  865|      0|                if (v != td->td_numberofinks)
  ------------------
  |  Branch (865:21): [True: 0, False: 0]
  ------------------
  866|      0|                {
  867|      0|                    TIFFErrorExtR(
  868|      0|                        tif, module,
  869|      0|                        "Error %s; Tag %s:\n  It is not possible to set the "
  870|      0|                        "value %" PRIu32
  871|      0|                        " for NumberOfInks\n  which is different from the "
  872|      0|                        "number of inks in the InkNames tag (%" PRIu16 ")",
  873|      0|                        tif->tif_name, fip->field_name, v, td->td_numberofinks);
  874|       |                    /* Do not set / overwrite number of inks already set by
  875|       |                     * InkNames case accordingly. */
  876|      0|                    status = 0;
  877|      0|                }
  878|      0|            }
  879|      0|            else
  880|      0|            {
  881|      0|                td->td_numberofinks = (uint16_t)v;
  882|      0|                if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  883|      0|                {
  884|      0|                    if (td->td_numberofinks != td->td_samplesperpixel)
  ------------------
  |  Branch (884:25): [True: 0, False: 0]
  ------------------
  885|      0|                    {
  886|      0|                        TIFFErrorExtR(tif, module,
  887|      0|                                      "Warning %s; Tag %s:\n  Value %" PRIu32
  888|      0|                                      " of NumberOfInks is different from the "
  889|      0|                                      "SamplesPerPixel value %" PRIu16 "",
  890|      0|                                      tif->tif_name, fip->field_name, v,
  891|      0|                                      td->td_samplesperpixel);
  892|      0|                    }
  893|      0|                }
  894|      0|            }
  895|      0|            break;
  896|      0|        case TIFFTAG_PERSAMPLE:
  ------------------
  |  |  752|      0|#define TIFFTAG_PERSAMPLE 65563        /* interface for per sample tags */
  ------------------
  |  Branch (896:9): [True: 0, False: 3.05k]
  ------------------
  897|      0|            v = (uint16_t)va_arg(ap, uint16_vap);
  898|      0|            if (v == PERSAMPLE_MULTI)
  ------------------
  |  |  754|      0|#define PERSAMPLE_MULTI 1              /* present as multiple values */
  ------------------
  |  Branch (898:17): [True: 0, False: 0]
  ------------------
  899|      0|                tif->tif_flags |= TIFF_PERSAMPLE;
  ------------------
  |  |  146|      0|#define TIFF_PERSAMPLE 0x400000U  /* get/set per sample tags as arrays */
  ------------------
  900|      0|            else
  901|      0|                tif->tif_flags &= ~TIFF_PERSAMPLE;
  ------------------
  |  |  146|      0|#define TIFF_PERSAMPLE 0x400000U  /* get/set per sample tags as arrays */
  ------------------
  902|      0|            break;
  903|      0|        default:
  ------------------
  |  Branch (903:9): [True: 0, False: 3.05k]
  ------------------
  904|      0|        {
  905|      0|            TIFFTagValue *tv;
  906|      0|            int tv_size, iCustom;
  907|       |
  908|       |            /*
  909|       |             * This can happen if multiple images are open with different
  910|       |             * codecs which have private tags.  The global tag information
  911|       |             * table may then have tags that are valid for one file but not
  912|       |             * the other. If the client tries to set a tag that is not valid
  913|       |             * for the image's codec then we'll arrive here.  This
  914|       |             * happens, for example, when tiffcp is used to convert between
  915|       |             * compression schemes and codec-specific tags are blindly copied.
  916|       |             *
  917|       |             * This also happens when a FIELD_IGNORE tag is written.
  918|       |             */
  919|      0|            if (fip->field_bit == FIELD_IGNORE)
  ------------------
  |  |  209|      0|#define FIELD_IGNORE 0
  ------------------
  |  Branch (919:17): [True: 0, False: 0]
  ------------------
  920|      0|            {
  921|      0|                TIFFErrorExtR(
  922|      0|                    tif, module,
  923|      0|                    "%s: Ignored %stag \"%s\" (not supported by libtiff)",
  924|      0|                    tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
  ------------------
  |  |  280|      0|#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  |  |  ------------------
  |  |  |  Branch (280:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  925|      0|                    fip->field_name);
  926|      0|                status = 0;
  927|      0|                break;
  928|      0|            }
  929|      0|            if (fip->field_bit != FIELD_CUSTOM)
  ------------------
  |  |  394|      0|#define FIELD_CUSTOM 65
  ------------------
  |  Branch (929:17): [True: 0, False: 0]
  ------------------
  930|      0|            {
  931|      0|                TIFFErrorExtR(
  932|      0|                    tif, module,
  933|      0|                    "%s: Invalid %stag \"%s\" (not supported by codec)",
  934|      0|                    tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
  ------------------
  |  |  280|      0|#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  |  |  ------------------
  |  |  |  Branch (280:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  935|      0|                    fip->field_name);
  936|      0|                status = 0;
  937|      0|                break;
  938|      0|            }
  939|       |
  940|       |            /*
  941|       |             * Find the existing entry for this custom value.
  942|       |             */
  943|      0|            tv = NULL;
  944|      0|            for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++)
  ------------------
  |  Branch (944:31): [True: 0, False: 0]
  ------------------
  945|      0|            {
  946|      0|                if (td->td_customValues[iCustom].info->field_tag == tag)
  ------------------
  |  Branch (946:21): [True: 0, False: 0]
  ------------------
  947|      0|                {
  948|      0|                    tv = td->td_customValues + iCustom;
  949|      0|                    old_custom_value = tv->value;
  950|      0|                    tv->value = NULL;
  951|      0|                    break;
  952|      0|                }
  953|      0|            }
  954|       |
  955|       |            /*
  956|       |             * Grow the custom list if the entry was not found.
  957|       |             */
  958|      0|            if (tv == NULL)
  ------------------
  |  Branch (958:17): [True: 0, False: 0]
  ------------------
  959|      0|            {
  960|      0|                TIFFTagValue *new_customValues;
  961|       |
  962|      0|                new_customValues = (TIFFTagValue *)_TIFFreallocExt(
  963|      0|                    tif, td->td_customValues,
  964|      0|                    (tmsize_t)(sizeof(TIFFTagValue) *
  965|      0|                               (size_t)(td->td_customValueCount + 1)));
  966|      0|                if (!new_customValues)
  ------------------
  |  Branch (966:21): [True: 0, False: 0]
  ------------------
  967|      0|                {
  968|      0|                    TIFFErrorExtR(tif, module,
  969|      0|                                  "%s: Failed to allocate space for list of "
  970|      0|                                  "custom values",
  971|      0|                                  tif->tif_name);
  972|      0|                    status = 0;
  973|      0|                    goto end;
  974|      0|                }
  975|       |
  976|      0|                td->td_customValueCount++;
  977|      0|                td->td_customValues = new_customValues;
  978|       |
  979|      0|                tv = td->td_customValues + (td->td_customValueCount - 1);
  980|      0|                tv->info = fip;
  981|      0|                tv->value = NULL;
  982|      0|                tv->count = 0;
  983|      0|            }
  984|       |
  985|       |            /*
  986|       |             * Set custom value ... save a copy of the custom tag value.
  987|       |             */
  988|       |            /*--: Rational2Double: For Rationals evaluate "set_get_field_type"
  989|       |             * to determine internal storage size. */
  990|      0|            tv_size = TIFFFieldSetGetSize(fip);
  991|      0|            if (tv_size == 0)
  ------------------
  |  Branch (991:17): [True: 0, False: 0]
  ------------------
  992|      0|            {
  993|      0|                status = 0;
  994|      0|                TIFFErrorExtR(tif, module, "%s: Bad field type %u for \"%s\"",
  995|      0|                              tif->tif_name, fip->field_type, fip->field_name);
  996|      0|                removeCustomValue(td, iCustom);
  997|      0|                goto end;
  998|      0|            }
  999|       |
 1000|      0|            if (fip->field_type == TIFF_ASCII)
  ------------------
  |  Branch (1000:17): [True: 0, False: 0]
  ------------------
 1001|      0|            {
 1002|      0|                uint32_t ma;
 1003|      0|                const char *mb;
 1004|      0|                if (fip->field_passcount)
  ------------------
  |  Branch (1004:21): [True: 0, False: 0]
  ------------------
 1005|      0|                {
 1006|      0|                    assert(fip->field_writecount == TIFF_VARIABLE2);
  ------------------
  |  Branch (1006:21): [True: 0, False: 0]
  |  Branch (1006:21): [True: 0, False: 0]
  ------------------
 1007|      0|                    ma = (uint32_t)va_arg(ap, uint32_t);
 1008|      0|                    mb = (const char *)va_arg(ap, const char *);
 1009|      0|                }
 1010|      0|                else
 1011|      0|                {
 1012|      0|                    mb = (const char *)va_arg(ap, const char *);
 1013|      0|                    size_t len = strlen(mb) + 1;
 1014|      0|                    if (len >= 0x80000000U)
  ------------------
  |  Branch (1014:25): [True: 0, False: 0]
  ------------------
 1015|      0|                    {
 1016|      0|                        status = 0;
 1017|      0|                        TIFFErrorExtR(tif, module,
 1018|      0|                                      "%s: Too long string value for \"%s\". "
 1019|      0|                                      "Maximum supported is 2147483647 bytes",
 1020|      0|                                      tif->tif_name, fip->field_name);
 1021|      0|                        removeCustomValue(td, iCustom);
 1022|      0|                        goto end;
 1023|      0|                    }
 1024|      0|                    ma = (uint32_t)len;
 1025|      0|                }
 1026|      0|                tv->count = (int)ma;
 1027|      0|                setByteArray(tif, &tv->value, mb, ma, 1);
 1028|      0|                if (!tv->value && ma != 0)
  ------------------
  |  Branch (1028:21): [True: 0, False: 0]
  |  Branch (1028:35): [True: 0, False: 0]
  ------------------
 1029|      0|                {
 1030|      0|                    removeCustomValue(td, iCustom);
 1031|      0|                    status = 0;
 1032|      0|                    goto end;
 1033|      0|                }
 1034|      0|            }
 1035|      0|            else
 1036|      0|            {
 1037|      0|                if (fip->field_passcount)
  ------------------
  |  Branch (1037:21): [True: 0, False: 0]
  ------------------
 1038|      0|                {
 1039|      0|                    if (fip->field_writecount == TIFF_VARIABLE2)
  ------------------
  |  |  392|      0|#define TIFF_VARIABLE2 -3    /* marker for uint32_t var-length tags */
  ------------------
  |  Branch (1039:25): [True: 0, False: 0]
  ------------------
 1040|      0|                        tv->count = (int)va_arg(ap, uint32_t);
 1041|      0|                    else
 1042|      0|                        tv->count = va_arg(ap, int);
 1043|      0|                }
 1044|      0|                else if (fip->field_writecount == TIFF_VARIABLE ||
  ------------------
  |  |  390|      0|#define TIFF_VARIABLE -1     /* marker for variable length tags */
  ------------------
  |  Branch (1044:26): [True: 0, False: 0]
  ------------------
 1045|      0|                         fip->field_writecount == TIFF_VARIABLE2)
  ------------------
  |  |  392|      0|#define TIFF_VARIABLE2 -3    /* marker for uint32_t var-length tags */
  ------------------
  |  Branch (1045:26): [True: 0, False: 0]
  ------------------
 1046|      0|                    tv->count = 1;
 1047|      0|                else if (fip->field_writecount == TIFF_SPP)
  ------------------
  |  |  391|      0|#define TIFF_SPP -2          /* marker for SamplesPerPixel tags */
  ------------------
  |  Branch (1047:26): [True: 0, False: 0]
  ------------------
 1048|      0|                    tv->count = td->td_samplesperpixel;
 1049|      0|                else
 1050|      0|                    tv->count = fip->field_writecount;
 1051|       |
 1052|      0|                if (tv->count == 0)
  ------------------
  |  Branch (1052:21): [True: 0, False: 0]
  ------------------
 1053|      0|                {
 1054|      0|                    TIFFWarningExtR(tif, module,
 1055|      0|                                    "%s: Null count for \"%s\" (type "
 1056|      0|                                    "%u, writecount %d, passcount %d)",
 1057|      0|                                    tif->tif_name, fip->field_name,
 1058|      0|                                    fip->field_type, fip->field_writecount,
 1059|      0|                                    fip->field_passcount);
 1060|      0|                    break;
 1061|      0|                }
 1062|       |
 1063|      0|                tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size,
 1064|      0|                                             "custom tag binary object");
 1065|      0|                if (!tv->value)
  ------------------
  |  Branch (1065:21): [True: 0, False: 0]
  ------------------
 1066|      0|                {
 1067|      0|                    removeCustomValue(td, iCustom);
 1068|      0|                    status = 0;
 1069|      0|                    goto end;
 1070|      0|                }
 1071|       |
 1072|      0|                if (fip->field_tag == TIFFTAG_DOTRANGE &&
  ------------------
  |  |  327|      0|#define TIFFTAG_DOTRANGE 336               /* !0% and 100% dot codes */
  ------------------
  |  Branch (1072:21): [True: 0, False: 0]
  ------------------
 1073|      0|                    strcmp(fip->field_name, "DotRange") == 0)
  ------------------
  |  Branch (1073:21): [True: 0, False: 0]
  ------------------
 1074|      0|                {
 1075|       |                    /* TODO: This is an evil exception and should not have been
 1076|       |                       handled this way ... likely best if we move it into
 1077|       |                       the directory structure with an explicit field in
 1078|       |                       libtiff 4.1 and assign it a FIELD_ value */
 1079|      0|                    uint16_t v2[2];
 1080|      0|                    v2[0] = (uint16_t)va_arg(ap, int);
 1081|      0|                    v2[1] = (uint16_t)va_arg(ap, int);
 1082|      0|                    _TIFFmemcpy(tv->value, &v2, 4);
 1083|      0|                }
 1084|       |
 1085|      0|                else if (fip->field_passcount ||
  ------------------
  |  Branch (1085:26): [True: 0, False: 0]
  ------------------
 1086|      0|                         fip->field_writecount == TIFF_VARIABLE ||
  ------------------
  |  |  390|      0|#define TIFF_VARIABLE -1     /* marker for variable length tags */
  ------------------
  |  Branch (1086:26): [True: 0, False: 0]
  ------------------
 1087|      0|                         fip->field_writecount == TIFF_VARIABLE2 ||
  ------------------
  |  |  392|      0|#define TIFF_VARIABLE2 -3    /* marker for uint32_t var-length tags */
  ------------------
  |  Branch (1087:26): [True: 0, False: 0]
  ------------------
 1088|      0|                         fip->field_writecount == TIFF_SPP || tv->count > 1)
  ------------------
  |  |  391|      0|#define TIFF_SPP -2          /* marker for SamplesPerPixel tags */
  ------------------
  |  Branch (1088:26): [True: 0, False: 0]
  |  Branch (1088:63): [True: 0, False: 0]
  ------------------
 1089|      0|                {
 1090|       |                    /*--: Rational2Double: For Rationals tv_size is set above to
 1091|       |                     * 4 or 8 according to fip->set_get_field_type! */
 1092|       |                    /* The size must be computed in tmsize_t: tv->count and
 1093|       |                     * tv_size are int, and their int product can overflow
 1094|       |                     * (and wrap to a bogus memcpy size) for counts that
 1095|       |                     * _TIFFCheckMalloc() above accepted, since it allows
 1096|       |                     * sizes up to TIFF_TMSIZE_T_MAX. */
 1097|      0|                    _TIFFmemcpy(tv->value, va_arg(ap, void *),
 1098|      0|                                (tmsize_t)tv->count * (tmsize_t)tv_size);
 1099|       |                    /* Test here for too big values for LONG8, IFD8, SLONG8 in
 1100|       |                     * ClassicTIFF and delete custom field from custom list */
 1101|      0|                    if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1101:25): [True: 0, False: 0]
  ------------------
 1102|      0|                    {
 1103|      0|                        if (tv->info->field_type == TIFF_LONG8 ||
  ------------------
  |  Branch (1103:29): [True: 0, False: 0]
  ------------------
 1104|      0|                            tv->info->field_type == TIFF_IFD8)
  ------------------
  |  Branch (1104:29): [True: 0, False: 0]
  ------------------
 1105|      0|                        {
 1106|      0|                            uint64_t *pui64 = (uint64_t *)tv->value;
 1107|      0|                            for (int i = 0; i < tv->count; i++)
  ------------------
  |  Branch (1107:45): [True: 0, False: 0]
  ------------------
 1108|      0|                            {
 1109|      0|                                if (pui64[i] > 0xffffffffu)
  ------------------
  |  Branch (1109:37): [True: 0, False: 0]
  ------------------
 1110|      0|                                {
 1111|      0|                                    TIFFErrorExtR(
 1112|      0|                                        tif, module,
 1113|      0|                                        "%s: Bad %s value %" PRIu64
 1114|      0|                                        " at %d. array position for \"%s\" tag "
 1115|      0|                                        "%u in ClassicTIFF. Tag won't be "
 1116|      0|                                        "written to file",
 1117|      0|                                        tif->tif_name,
 1118|      0|                                        (tv->info->field_type == TIFF_LONG8
  ------------------
  |  Branch (1118:42): [True: 0, False: 0]
  ------------------
 1119|      0|                                             ? "LONG8"
 1120|      0|                                             : "IFD8"),
 1121|      0|                                        pui64[i], i, fip->field_name, tag);
 1122|      0|                                    goto badvalueifd8long8;
 1123|      0|                                }
 1124|      0|                            }
 1125|      0|                        }
 1126|      0|                        else if (tv->info->field_type == TIFF_SLONG8)
  ------------------
  |  Branch (1126:34): [True: 0, False: 0]
  ------------------
 1127|      0|                        {
 1128|      0|                            int64_t *pi64 = (int64_t *)tv->value;
 1129|      0|                            for (int i = 0; i < tv->count; i++)
  ------------------
  |  Branch (1129:45): [True: 0, False: 0]
  ------------------
 1130|      0|                            {
 1131|      0|                                if (pi64[i] > 2147483647 ||
  ------------------
  |  Branch (1131:37): [True: 0, False: 0]
  ------------------
 1132|      0|                                    pi64[i] < (-2147483647 - 1))
  ------------------
  |  Branch (1132:37): [True: 0, False: 0]
  ------------------
 1133|      0|                                {
 1134|      0|                                    TIFFErrorExtR(
 1135|      0|                                        tif, module,
 1136|      0|                                        "%s: Bad SLONG8 value %" PRIi64
 1137|      0|                                        " at %d. array position for \"%s\" tag "
 1138|      0|                                        "%u in ClassicTIFF. Tag won't be "
 1139|      0|                                        "written to file",
 1140|      0|                                        tif->tif_name, pi64[i], i,
 1141|      0|                                        fip->field_name, tag);
 1142|      0|                                    goto badvalueifd8long8;
 1143|      0|                                }
 1144|      0|                            }
 1145|      0|                        }
 1146|      0|                    }
 1147|      0|                }
 1148|      0|                else
 1149|      0|                {
 1150|      0|                    char *val = (char *)tv->value;
 1151|      0|                    assert(tv->count == 1);
  ------------------
  |  Branch (1151:21): [True: 0, False: 0]
  |  Branch (1151:21): [True: 0, False: 0]
  ------------------
 1152|       |
 1153|      0|                    switch (fip->field_type)
 1154|      0|                    {
 1155|      0|                        case TIFF_BYTE:
  ------------------
  |  Branch (1155:25): [True: 0, False: 0]
  ------------------
 1156|      0|                        case TIFF_UNDEFINED:
  ------------------
  |  Branch (1156:25): [True: 0, False: 0]
  ------------------
 1157|      0|                        {
 1158|      0|                            uint8_t v2 = (uint8_t)va_arg(ap, int);
 1159|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1160|      0|                        }
 1161|      0|                        break;
 1162|      0|                        case TIFF_SBYTE:
  ------------------
  |  Branch (1162:25): [True: 0, False: 0]
  ------------------
 1163|      0|                        {
 1164|      0|                            int8_t v2 = (int8_t)va_arg(ap, int);
 1165|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1166|      0|                        }
 1167|      0|                        break;
 1168|      0|                        case TIFF_SHORT:
  ------------------
  |  Branch (1168:25): [True: 0, False: 0]
  ------------------
 1169|      0|                        {
 1170|      0|                            uint16_t v2 = (uint16_t)va_arg(ap, int);
 1171|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1172|      0|                        }
 1173|      0|                        break;
 1174|      0|                        case TIFF_SSHORT:
  ------------------
  |  Branch (1174:25): [True: 0, False: 0]
  ------------------
 1175|      0|                        {
 1176|      0|                            int16_t v2 = (int16_t)va_arg(ap, int);
 1177|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1178|      0|                        }
 1179|      0|                        break;
 1180|      0|                        case TIFF_LONG:
  ------------------
  |  Branch (1180:25): [True: 0, False: 0]
  ------------------
 1181|      0|                        case TIFF_IFD:
  ------------------
  |  Branch (1181:25): [True: 0, False: 0]
  ------------------
 1182|      0|                        {
 1183|      0|                            uint32_t v2 = va_arg(ap, uint32_t);
 1184|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1185|      0|                        }
 1186|      0|                        break;
 1187|      0|                        case TIFF_SLONG:
  ------------------
  |  Branch (1187:25): [True: 0, False: 0]
  ------------------
 1188|      0|                        {
 1189|      0|                            int32_t v2 = va_arg(ap, int32_t);
 1190|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1191|      0|                        }
 1192|      0|                        break;
 1193|      0|                        case TIFF_LONG8:
  ------------------
  |  Branch (1193:25): [True: 0, False: 0]
  ------------------
 1194|      0|                        case TIFF_IFD8:
  ------------------
  |  Branch (1194:25): [True: 0, False: 0]
  ------------------
 1195|      0|                        {
 1196|      0|                            uint64_t v2 = va_arg(ap, uint64_t);
 1197|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1198|       |                            /* Test here for too big values for ClassicTIFF and
 1199|       |                             * delete custom field from custom list */
 1200|      0|                            if (!(tif->tif_flags & TIFF_BIGTIFF) &&
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1200:33): [True: 0, False: 0]
  ------------------
 1201|      0|                                (v2 > 0xffffffffu))
  ------------------
  |  Branch (1201:33): [True: 0, False: 0]
  ------------------
 1202|      0|                            {
 1203|      0|                                TIFFErrorExtR(
 1204|      0|                                    tif, module,
 1205|      0|                                    "%s: Bad LONG8 or IFD8 value %" PRIu64
 1206|      0|                                    " for \"%s\" tag %u in ClassicTIFF. Tag "
 1207|      0|                                    "won't be written to file",
 1208|      0|                                    tif->tif_name, v2, fip->field_name, tag);
 1209|      0|                                goto badvalueifd8long8;
 1210|      0|                            }
 1211|      0|                        }
 1212|      0|                        break;
 1213|      0|                        case TIFF_SLONG8:
  ------------------
  |  Branch (1213:25): [True: 0, False: 0]
  ------------------
 1214|      0|                        {
 1215|      0|                            int64_t v2 = va_arg(ap, int64_t);
 1216|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1217|       |                            /* Test here for too big values for ClassicTIFF and
 1218|       |                             * delete custom field from custom list */
 1219|      0|                            if (!(tif->tif_flags & TIFF_BIGTIFF) &&
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1219:33): [True: 0, False: 0]
  ------------------
 1220|      0|                                ((v2 > 2147483647) || (v2 < (-2147483647 - 1))))
  ------------------
  |  Branch (1220:34): [True: 0, False: 0]
  |  Branch (1220:55): [True: 0, False: 0]
  ------------------
 1221|      0|                            {
 1222|      0|                                TIFFErrorExtR(
 1223|      0|                                    tif, module,
 1224|      0|                                    "%s: Bad SLONG8 value %" PRIi64
 1225|      0|                                    " for \"%s\" tag %u in ClassicTIFF. Tag "
 1226|      0|                                    "won't be written to file",
 1227|      0|                                    tif->tif_name, v2, fip->field_name, tag);
 1228|      0|                                goto badvalueifd8long8;
 1229|      0|                            }
 1230|      0|                        }
 1231|      0|                        break;
 1232|      0|                        case TIFF_RATIONAL:
  ------------------
  |  Branch (1232:25): [True: 0, False: 0]
  ------------------
 1233|      0|                        case TIFF_SRATIONAL:
  ------------------
  |  Branch (1233:25): [True: 0, False: 0]
  ------------------
 1234|       |                            /*-- Rational2Double: For Rationals tv_size is set
 1235|       |                             * above to 4 or 8 according to
 1236|       |                             * fip->set_get_field_type!
 1237|       |                             */
 1238|      0|                            {
 1239|      0|                                if (tv_size == 8)
  ------------------
  |  Branch (1239:37): [True: 0, False: 0]
  ------------------
 1240|      0|                                {
 1241|      0|                                    double v2 = va_arg(ap, double);
 1242|      0|                                    _TIFFmemcpy(val, &v2, tv_size);
 1243|      0|                                }
 1244|      0|                                else
 1245|      0|                                {
 1246|       |                                    /*-- default should be tv_size == 4 */
 1247|      0|                                    float v3 = (float)va_arg(ap, double);
 1248|      0|                                    _TIFFmemcpy(val, &v3, tv_size);
 1249|       |                                    /*-- ToDo: After Testing, this should be
 1250|       |                                     * removed and tv_size==4 should be set as
 1251|       |                                     * default. */
 1252|      0|                                    if (tv_size != 4)
  ------------------
  |  Branch (1252:41): [True: 0, False: 0]
  ------------------
 1253|      0|                                    {
 1254|      0|                                        TIFFErrorExtR(tif, module,
 1255|      0|                                                      "Rational2Double: "
 1256|      0|                                                      ".set_get_field_type "
 1257|      0|                                                      "in not 4 but %d",
 1258|      0|                                                      tv_size);
 1259|      0|                                    }
 1260|      0|                                }
 1261|      0|                            }
 1262|      0|                            break;
 1263|      0|                        case TIFF_FLOAT:
  ------------------
  |  Branch (1263:25): [True: 0, False: 0]
  ------------------
 1264|      0|                        {
 1265|      0|                            float v2 =
 1266|      0|                                _TIFFClampDoubleToFloat(va_arg(ap, double));
 1267|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1268|      0|                        }
 1269|      0|                        break;
 1270|      0|                        case TIFF_DOUBLE:
  ------------------
  |  Branch (1270:25): [True: 0, False: 0]
  ------------------
 1271|      0|                        {
 1272|      0|                            double v2 = va_arg(ap, double);
 1273|      0|                            _TIFFmemcpy(val, &v2, tv_size);
 1274|      0|                        }
 1275|      0|                        break;
 1276|      0|                        case TIFF_NOTYPE:
  ------------------
  |  Branch (1276:25): [True: 0, False: 0]
  ------------------
 1277|      0|                        case TIFF_ASCII:
  ------------------
  |  Branch (1277:25): [True: 0, False: 0]
  ------------------
 1278|      0|                        default:
  ------------------
  |  Branch (1278:25): [True: 0, False: 0]
  ------------------
 1279|      0|                            _TIFFmemset(val, 0, tv_size);
 1280|      0|                            status = 0;
 1281|      0|                            break;
 1282|      0|                    }
 1283|      0|                }
 1284|      0|            }
 1285|      0|            if (old_custom_value)
  ------------------
  |  Branch (1285:17): [True: 0, False: 0]
  ------------------
 1286|      0|            {
 1287|      0|                _TIFFfreeExt(tif, old_custom_value);
 1288|      0|                old_custom_value = NULL;
 1289|      0|            }
 1290|      0|        }
 1291|  3.05k|    }
 1292|  3.05k|    if (status)
  ------------------
  |  Branch (1292:9): [True: 3.05k, False: 0]
  ------------------
 1293|  3.05k|    {
 1294|  3.05k|        const TIFFField *fip2 = TIFFFieldWithTag(tif, tag);
 1295|  3.05k|        if (fip2)
  ------------------
  |  Branch (1295:13): [True: 3.05k, False: 0]
  ------------------
 1296|  3.05k|            TIFFSetFieldBit(tif, fip2->field_bit);
  ------------------
  |  |  268|  3.05k|#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  266|  3.05k|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  265|  3.05k|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
 1297|  3.05k|        tif->tif_flags |= TIFF_DIRTYDIRECT;
  ------------------
  |  |  125|  3.05k|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
 1298|  3.05k|    }
 1299|       |
 1300|  3.05k|end:
 1301|  3.05k|    if (old_custom_value)
  ------------------
  |  Branch (1301:9): [True: 0, False: 3.05k]
  ------------------
 1302|      0|        _TIFFfreeExt(tif, old_custom_value);
 1303|  3.05k|    va_end(ap);
 1304|  3.05k|    return (status);
 1305|      0|badvalue:
 1306|      0|{
 1307|      0|    const TIFFField *fip2 = TIFFFieldWithTag(tif, tag);
 1308|      0|    TIFFErrorExtR(tif, module, "%s: Bad value %" PRIu32 " for \"%s\" tag",
 1309|      0|                  tif->tif_name, v, fip2 ? fip2->field_name : "Unknown");
  ------------------
  |  Branch (1309:37): [True: 0, False: 0]
  ------------------
 1310|      0|    va_end(ap);
 1311|      0|}
 1312|      0|    return (0);
 1313|      0|badvalue32:
 1314|      0|{
 1315|      0|    const TIFFField *fip2 = TIFFFieldWithTag(tif, tag);
 1316|      0|    TIFFErrorExtR(tif, module, "%s: Bad value %" PRIu32 " for \"%s\" tag",
 1317|      0|                  tif->tif_name, v32, fip2 ? fip2->field_name : "Unknown");
  ------------------
  |  Branch (1317:39): [True: 0, False: 0]
  ------------------
 1318|      0|    va_end(ap);
 1319|      0|}
 1320|      0|    return (0);
 1321|      0|badvaluedouble:
 1322|      0|{
 1323|      0|    const TIFFField *fip2 = TIFFFieldWithTag(tif, tag);
 1324|      0|    TIFFErrorExtR(tif, module, "%s: Bad value %f for \"%s\" tag", tif->tif_name,
 1325|      0|                  dblval, fip2 ? fip2->field_name : "Unknown");
  ------------------
  |  Branch (1325:27): [True: 0, False: 0]
  ------------------
 1326|      0|    va_end(ap);
 1327|      0|}
 1328|      0|    return (0);
 1329|      0|badvalueifd8long8:
 1330|      0|{
 1331|       |    /* Error message issued already above. */
 1332|      0|    TIFFTagValue *tv2 = NULL;
 1333|      0|    int iCustom2, iC2;
 1334|       |    /* Find the existing entry for this custom value. */
 1335|      0|    for (iCustom2 = 0; iCustom2 < td->td_customValueCount; iCustom2++)
  ------------------
  |  Branch (1335:24): [True: 0, False: 0]
  ------------------
 1336|      0|    {
 1337|      0|        if (td->td_customValues[iCustom2].info->field_tag == tag)
  ------------------
  |  Branch (1337:13): [True: 0, False: 0]
  ------------------
 1338|      0|        {
 1339|      0|            tv2 = td->td_customValues + (iCustom2);
 1340|      0|            break;
 1341|      0|        }
 1342|      0|    }
 1343|      0|    if (tv2 != NULL)
  ------------------
  |  Branch (1343:9): [True: 0, False: 0]
  ------------------
 1344|      0|    {
 1345|       |        /* Remove custom field from custom list */
 1346|      0|        if (tv2->value != NULL)
  ------------------
  |  Branch (1346:13): [True: 0, False: 0]
  ------------------
 1347|      0|        {
 1348|      0|            _TIFFfreeExt(tif, tv2->value);
 1349|      0|            tv2->value = NULL;
 1350|      0|        }
 1351|       |        /* Shorten list and close gap in customValues list.
 1352|       |         * Re-allocation of td_customValues not necessary here. */
 1353|      0|        td->td_customValueCount--;
 1354|      0|        for (iC2 = iCustom2; iC2 < td->td_customValueCount; iC2++)
  ------------------
  |  Branch (1354:30): [True: 0, False: 0]
  ------------------
 1355|      0|        {
 1356|      0|            td->td_customValues[iC2] = td->td_customValues[iC2 + 1];
 1357|      0|        }
 1358|      0|    }
 1359|      0|    else
 1360|      0|    {
 1361|      0|        assert(0);
  ------------------
  |  Branch (1361:9): [Folded, False: 0]
  |  Branch (1361:9): [Folded, False: 0]
  ------------------
 1362|      0|    }
 1363|      0|    if (old_custom_value)
  ------------------
  |  Branch (1363:9): [True: 0, False: 0]
  ------------------
 1364|      0|        _TIFFfreeExt(tif, old_custom_value);
 1365|       |    va_end(ap);
 1366|      0|}
 1367|      0|    return (0);
 1368|      0|} /*-- _TIFFVSetField() --*/

_TIFFGetFields:
  561|    380|const TIFFFieldArray *_TIFFGetFields(void) { return (&tiffFieldArray); }
_TIFFSetupFields:
  568|    380|{
  569|    380|    if (tif->tif_fields && tif->tif_nfields > 0)
  ------------------
  |  Branch (569:9): [True: 170, False: 210]
  |  Branch (569:28): [True: 170, False: 0]
  ------------------
  570|    170|    {
  571|    170|        uint32_t i;
  572|       |
  573|  26.1k|        for (i = 0; i < tif->tif_nfields; i++)
  ------------------
  |  Branch (573:21): [True: 26.0k, False: 170]
  ------------------
  574|  26.0k|        {
  575|  26.0k|            TIFFField *fld = tif->tif_fields[i];
  576|  26.0k|            if (fld->field_name != NULL)
  ------------------
  |  Branch (576:17): [True: 26.0k, False: 0]
  ------------------
  577|  26.0k|            {
  578|  26.0k|                if (fld->field_bit == FIELD_CUSTOM && TIFFFieldIsAnonymous(fld))
  ------------------
  |  |  394|  52.0k|#define FIELD_CUSTOM 65
  ------------------
  |  Branch (578:21): [True: 17.5k, False: 8.50k]
  |  Branch (578:55): [True: 0, False: 17.5k]
  ------------------
  579|      0|                {
  580|      0|                    _TIFFfreeExt(tif, (void *)fld->field_name);
  581|       |                    /* caution: tif_fields[i] must not be the beginning of a
  582|       |                     * fields-array. Otherwise the following tags are also freed
  583|       |                     * with the first free().
  584|       |                     */
  585|      0|                    _TIFFfreeExt(tif, fld);
  586|      0|                }
  587|  26.0k|            }
  588|  26.0k|        }
  589|       |
  590|    170|        _TIFFfreeExt(tif, tif->tif_fields);
  591|    170|        tif->tif_fields = NULL;
  592|    170|        tif->tif_nfields = 0;
  593|    170|    }
  594|    380|    if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count))
  ------------------
  |  Branch (594:9): [True: 0, False: 380]
  ------------------
  595|      0|    {
  596|      0|        TIFFErrorExtR(tif, "_TIFFSetupFields", "Setting up field info failed");
  597|      0|    }
  598|    380|}
_TIFFMergeFields:
  628|    380|{
  629|    380|    static const char module[] = "_TIFFMergeFields";
  630|    380|    static const char reason[] = "for fields array";
  631|       |    /* TIFFField** tp; */
  632|    380|    uint32_t i;
  633|       |
  634|    380|    tif->tif_foundfield = NULL;
  635|       |
  636|    380|    TIFFField **tif_newfields = NULL;
  637|       |
  638|    380|    if (tif->tif_fields && tif->tif_nfields > 0)
  ------------------
  |  Branch (638:9): [True: 0, False: 380]
  |  Branch (638:28): [True: 0, False: 0]
  ------------------
  639|      0|    {
  640|      0|        tif_newfields = (TIFFField **)_TIFFCheckRealloc(
  641|      0|            tif, tif->tif_fields, (tmsize_t)tif->tif_nfields + n,
  642|      0|            (tmsize_t)sizeof(TIFFField *), reason);
  643|      0|    }
  644|    380|    else
  645|    380|    {
  646|    380|        tif_newfields =
  647|    380|            (TIFFField **)_TIFFCheckMalloc(tif, n, sizeof(TIFFField *), reason);
  648|    380|    }
  649|    380|    if (!tif_newfields)
  ------------------
  |  Branch (649:9): [True: 0, False: 380]
  ------------------
  650|      0|    {
  651|      0|        TIFFErrorExtR(tif, module, "Failed to allocate fields array");
  652|      0|        return 0;
  653|      0|    }
  654|    380|    tif->tif_fields = tif_newfields;
  655|       |
  656|       |    /* tp = tif->tif_fields + tif->tif_nfields; */
  657|  58.5k|    for (i = 0; i < n; i++)
  ------------------
  |  Branch (657:17): [True: 58.1k, False: 380]
  ------------------
  658|  58.1k|    {
  659|  58.1k|        const TIFFField *fip = TIFFFindField(tif, info[i].field_tag, TIFF_ANY);
  ------------------
  |  |  389|  58.1k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
  660|       |
  661|       |        /* only add definitions that aren't already present */
  662|  58.1k|        if (!fip)
  ------------------
  |  Branch (662:13): [True: 58.1k, False: 0]
  ------------------
  663|  58.1k|        {
  664|  58.1k|            tif->tif_fields[tif->tif_nfields] = (TIFFField *)(info + i);
  665|  58.1k|            tif->tif_nfields++;
  666|  58.1k|        }
  667|  58.1k|    }
  668|       |
  669|       |    /* Sort the field info by tag number */
  670|    380|    qsort(tif->tif_fields, tif->tif_nfields, sizeof(TIFFField *), tagCompare);
  671|       |
  672|    380|    return (int)n;
  673|    380|}
TIFFFindField:
  881|  67.3k|{
  882|  67.3k|    TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0,   TIFF_SETGET_UNDEFINED,
  883|  67.3k|                     0, 0, 0, NULL,        NULL};
  884|  67.3k|    TIFFField *pkey = &key;
  885|  67.3k|    const TIFFField **ret;
  886|  67.3k|    if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag &&
  ------------------
  |  Branch (886:9): [True: 8.78k, False: 58.5k]
  |  Branch (886:32): [True: 6.31k, False: 2.46k]
  ------------------
  887|  6.31k|        (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
  ------------------
  |  |  389|  12.6k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
  |  Branch (887:10): [True: 6.31k, False: 0]
  |  Branch (887:28): [True: 0, False: 0]
  ------------------
  888|  6.31k|        return tif->tif_foundfield;
  889|       |
  890|       |    /* If we are invoked with no field information, then just return. */
  891|  60.9k|    if (!tif->tif_fields)
  ------------------
  |  Branch (891:9): [True: 0, False: 60.9k]
  ------------------
  892|      0|        return NULL;
  893|       |
  894|       |    /* NB: use sorted search (e.g. binary search) */
  895|       |
  896|  60.9k|    key.field_tag = tag;
  897|  60.9k|    key.field_type = dt;
  898|       |
  899|  60.9k|    ret = (const TIFFField **)bsearch(&pkey, tif->tif_fields, tif->tif_nfields,
  900|  60.9k|                                      sizeof(TIFFField *), tagCompare);
  901|  60.9k|    return tif->tif_foundfield = (ret ? *ret : NULL);
  ------------------
  |  Branch (901:35): [True: 2.84k, False: 58.1k]
  ------------------
  902|  60.9k|}
TIFFFieldWithTag:
  933|  3.05k|{
  934|  3.05k|    const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
  ------------------
  |  |  389|  3.05k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
  935|  3.05k|    if (!fip)
  ------------------
  |  Branch (935:9): [True: 0, False: 3.05k]
  ------------------
  936|      0|    {
  937|      0|        if (tif->tif_warn_about_unknown_tags)
  ------------------
  |  Branch (937:13): [True: 0, False: 0]
  ------------------
  938|      0|        {
  939|      0|            TIFFWarningExtR(tif, "TIFFFieldWithTag",
  940|      0|                            "Warning, unknown tag 0x%x", (unsigned int)tag);
  941|      0|        }
  942|      0|    }
  943|  3.05k|    return (fip);
  944|  3.05k|}
TIFFFieldIsAnonymous:
  973|  39.1k|{
  974|  39.1k|    return (int)fip->field_anonymous;
  975|  39.1k|}
tif_dirinfo.c:tagCompare:
  601|   560k|{
  602|   560k|    const TIFFField *ta = *(const TIFFField **)a;
  603|   560k|    const TIFFField *tb = *(const TIFFField **)b;
  604|       |    /* NB: be careful of return values for 16-bit platforms */
  605|   560k|    if (ta->field_tag != tb->field_tag)
  ------------------
  |  Branch (605:9): [True: 558k, False: 2.84k]
  ------------------
  606|   558k|        return (int)ta->field_tag - (int)tb->field_tag;
  607|  2.84k|    else
  608|  2.84k|        return (ta->field_type == TIFF_ANY)
  ------------------
  |  |  389|  2.84k|#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
  ------------------
  |  Branch (608:16): [True: 2.84k, False: 0]
  ------------------
  609|  2.84k|                   ? 0
  610|  2.84k|                   : ((int)tb->field_type - (int)ta->field_type);
  611|   560k|}

_TIFFCheckDirNumberAndOffset:
 5807|    170|{
 5808|    170|    if (diroff == 0) /* no more directories */
  ------------------
  |  Branch (5808:9): [True: 0, False: 170]
  ------------------
 5809|      0|        return 0;
 5810|       |
 5811|    170|    if (tif->tif_map_dir_offset_to_number == NULL)
  ------------------
  |  Branch (5811:9): [True: 170, False: 0]
  ------------------
 5812|    170|    {
 5813|    170|        tif->tif_map_dir_offset_to_number = TIFFHashSetNew(
 5814|    170|            tif, hashFuncOffsetToNumber, equalFuncOffsetToNumber, _TIFFfreeExt);
 5815|    170|        if (tif->tif_map_dir_offset_to_number == NULL)
  ------------------
  |  Branch (5815:13): [True: 0, False: 170]
  ------------------
 5816|      0|        {
 5817|      0|            TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5818|      0|                          "Not enough memory");
 5819|      0|            return 0;
 5820|      0|        }
 5821|    170|    }
 5822|       |
 5823|    170|    if (tif->tif_map_dir_number_to_offset == NULL)
  ------------------
  |  Branch (5823:9): [True: 170, False: 0]
  ------------------
 5824|    170|    {
 5825|       |        /* No free callback for this map, as it shares the same items as
 5826|       |         * tif->tif_map_dir_offset_to_number. */
 5827|    170|        tif->tif_map_dir_number_to_offset = TIFFHashSetNew(
 5828|    170|            tif, hashFuncNumberToOffset, equalFuncNumberToOffset, NULL);
 5829|    170|        if (tif->tif_map_dir_number_to_offset == NULL)
  ------------------
  |  Branch (5829:13): [True: 0, False: 170]
  ------------------
 5830|      0|        {
 5831|      0|            TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5832|      0|                          "Not enough memory");
 5833|      0|            return 0;
 5834|      0|        }
 5835|    170|    }
 5836|       |
 5837|       |    /* Check if offset is already in the list:
 5838|       |     * - yes: check, if offset is at the same IFD number - if not, it is an IFD
 5839|       |     * loop
 5840|       |     * -  no: add to list or update offset at that IFD number
 5841|       |     */
 5842|    170|    TIFFOffsetAndDirNumber entry;
 5843|    170|    entry.offset = diroff;
 5844|    170|    entry.dirNumber = dirn;
 5845|       |
 5846|    170|    TIFFOffsetAndDirNumber *foundEntry =
 5847|    170|        (TIFFOffsetAndDirNumber *)TIFFHashSetLookup(
 5848|    170|            tif->tif_map_dir_offset_to_number, &entry);
 5849|    170|    if (foundEntry)
  ------------------
  |  Branch (5849:9): [True: 0, False: 170]
  ------------------
 5850|      0|    {
 5851|      0|        if (foundEntry->dirNumber == dirn)
  ------------------
  |  Branch (5851:13): [True: 0, False: 0]
  ------------------
 5852|      0|        {
 5853|      0|            return 1;
 5854|      0|        }
 5855|      0|        else
 5856|      0|        {
 5857|      0|            TIFFWarningExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5858|      0|                            "TIFF directory %d has IFD looping to directory %u "
 5859|      0|                            "at offset 0x%" PRIx64 " (%" PRIu64 ")",
 5860|      0|                            (int)dirn - 1, foundEntry->dirNumber, diroff,
 5861|      0|                            diroff);
 5862|      0|            return 0;
 5863|      0|        }
 5864|      0|    }
 5865|       |
 5866|       |    /* Check if offset of an IFD has been changed and update offset of that IFD
 5867|       |     * number. */
 5868|    170|    foundEntry = (TIFFOffsetAndDirNumber *)TIFFHashSetLookup(
 5869|    170|        tif->tif_map_dir_number_to_offset, &entry);
 5870|    170|    if (foundEntry)
  ------------------
  |  Branch (5870:9): [True: 0, False: 170]
  ------------------
 5871|      0|    {
 5872|      0|        if (foundEntry->offset != diroff)
  ------------------
  |  Branch (5872:13): [True: 0, False: 0]
  ------------------
 5873|      0|        {
 5874|      0|            TIFFOffsetAndDirNumber entryOld;
 5875|      0|            entryOld.offset = foundEntry->offset;
 5876|      0|            entryOld.dirNumber = dirn;
 5877|       |            /* We must remove first from tif_map_dir_number_to_offset as the */
 5878|       |            /* entry is owned (and thus freed) by */
 5879|       |            /* tif_map_dir_offset_to_number */
 5880|      0|            TIFFOffsetAndDirNumber *foundEntryOld =
 5881|      0|                (TIFFOffsetAndDirNumber *)TIFFHashSetLookup(
 5882|      0|                    tif->tif_map_dir_number_to_offset, &entryOld);
 5883|      0|            if (foundEntryOld)
  ------------------
  |  Branch (5883:17): [True: 0, False: 0]
  ------------------
 5884|      0|            {
 5885|      0|                TIFFHashSetRemove(tif->tif_map_dir_number_to_offset,
 5886|      0|                                  foundEntryOld);
 5887|      0|            }
 5888|      0|            foundEntryOld = (TIFFOffsetAndDirNumber *)TIFFHashSetLookup(
 5889|      0|                tif->tif_map_dir_offset_to_number, &entryOld);
 5890|      0|            if (foundEntryOld)
  ------------------
  |  Branch (5890:17): [True: 0, False: 0]
  ------------------
 5891|      0|            {
 5892|      0|                TIFFHashSetRemove(tif->tif_map_dir_offset_to_number,
 5893|      0|                                  foundEntryOld);
 5894|      0|            }
 5895|       |
 5896|      0|            TIFFOffsetAndDirNumber *entryPtr =
 5897|      0|                (TIFFOffsetAndDirNumber *)_TIFFmallocExt(
 5898|      0|                    tif, sizeof(TIFFOffsetAndDirNumber));
 5899|      0|            if (entryPtr == NULL)
  ------------------
  |  Branch (5899:17): [True: 0, False: 0]
  ------------------
 5900|      0|            {
 5901|      0|                return 0;
 5902|      0|            }
 5903|       |
 5904|       |            /* Add IFD offset and dirn to IFD directory list */
 5905|      0|            *entryPtr = entry;
 5906|       |
 5907|      0|            if (!insertOffsetAndDirNumber(tif, entryPtr))
  ------------------
  |  Branch (5907:17): [True: 0, False: 0]
  ------------------
 5908|      0|            {
 5909|      0|                return 0;
 5910|      0|            }
 5911|      0|        }
 5912|      0|        return 1;
 5913|      0|    }
 5914|       |
 5915|       |    /* Arbitrary (hopefully big enough) limit */
 5916|    170|    if (TIFFHashSetSize(tif->tif_map_dir_offset_to_number) >=
  ------------------
  |  Branch (5916:9): [True: 0, False: 170]
  ------------------
 5917|    170|        TIFF_MAX_DIR_COUNT)
  ------------------
  |  |  122|    170|#define TIFF_MAX_DIR_COUNT 1048576
  ------------------
 5918|      0|    {
 5919|      0|        TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5920|      0|                      "Cannot handle more than %u TIFF directories",
 5921|      0|                      (unsigned)TIFF_MAX_DIR_COUNT);
  ------------------
  |  |  122|      0|#define TIFF_MAX_DIR_COUNT 1048576
  ------------------
 5922|      0|        return 0;
 5923|      0|    }
 5924|       |
 5925|    170|    TIFFOffsetAndDirNumber *entryPtr = (TIFFOffsetAndDirNumber *)_TIFFmallocExt(
 5926|    170|        tif, sizeof(TIFFOffsetAndDirNumber));
 5927|    170|    if (entryPtr == NULL)
  ------------------
  |  Branch (5927:9): [True: 0, False: 170]
  ------------------
 5928|      0|    {
 5929|      0|        TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5930|      0|                      "Cannot allocate directory tracking entry");
 5931|      0|        return 0;
 5932|      0|    }
 5933|       |
 5934|       |    /* Add IFD offset and dirn to IFD directory list */
 5935|    170|    *entryPtr = entry;
 5936|       |
 5937|    170|    if (!insertOffsetAndDirNumber(tif, entryPtr))
  ------------------
  |  Branch (5937:9): [True: 0, False: 170]
  ------------------
 5938|      0|    {
 5939|      0|        return 0;
 5940|      0|    }
 5941|       |
 5942|    170|    return 1;
 5943|    170|} /* --- _TIFFCheckDirNumberAndOffset() ---*/
_TIFFFillStriles:
 8570|    417|int _TIFFFillStriles(TIFF *tif) { return _TIFFFillStrilesInternal(tif, 1); }
tif_dirread.c:hashFuncOffsetToNumber:
 5730|    510|{
 5731|    510|    const TIFFOffsetAndDirNumber *offsetAndDirNumber =
 5732|    510|        (const TIFFOffsetAndDirNumber *)elt;
 5733|    510|    const uint32_t hash = (uint32_t)(offsetAndDirNumber->offset >> 32) ^
 5734|    510|                          ((uint32_t)offsetAndDirNumber->offset & 0xFFFFFFFFU);
 5735|    510|    return hash;
 5736|    510|}
tif_dirread.c:hashFuncNumberToOffset:
 5748|    510|{
 5749|    510|    const TIFFOffsetAndDirNumber *offsetAndDirNumber =
 5750|    510|        (const TIFFOffsetAndDirNumber *)elt;
 5751|    510|    return offsetAndDirNumber->dirNumber;
 5752|    510|}
tif_dirread.c:insertOffsetAndDirNumber:
 5775|    170|{
 5776|    170|    if (!TIFFHashSetInsert(tif->tif_map_dir_offset_to_number, entryPtr))
  ------------------
  |  Branch (5776:9): [True: 0, False: 170]
  ------------------
 5777|      0|    {
 5778|      0|        TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5779|      0|                      "Insertion in tif_map_dir_offset_to_number failed");
 5780|      0|        return false;
 5781|      0|    }
 5782|    170|    if (!TIFFHashSetInsert(tif->tif_map_dir_number_to_offset, entryPtr))
  ------------------
  |  Branch (5782:9): [True: 0, False: 170]
  ------------------
 5783|      0|    {
 5784|      0|        TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5785|      0|                      "Insertion in tif_map_dir_number_to_offset failed");
 5786|      0|        if (!TIFFHashSetRemove(tif->tif_map_dir_offset_to_number, entryPtr))
  ------------------
  |  Branch (5786:13): [True: 0, False: 0]
  ------------------
 5787|      0|        {
 5788|      0|            TIFFErrorExtR(tif, "_TIFFCheckDirNumberAndOffset",
 5789|      0|                          "Rollback of directory tracking entry failed");
 5790|      0|        }
 5791|      0|        return false;
 5792|      0|    }
 5793|    170|    return true;
 5794|    170|}
tif_dirread.c:_TIFFFillStrilesInternal:
 8573|    417|{
 8574|    417|    TIFFDirectory *td = &tif->tif_dir;
 8575|    417|    int return_value = 1;
 8576|       |
 8577|       |    /* Do not do anything if TIFF_DEFERSTRILELOAD is not set */
 8578|    417|    if (!(tif->tif_flags & TIFF_DEFERSTRILELOAD) ||
  ------------------
  |  |  150|    417|    0x1000000U /* defer strip/tile offset/bytecount array loading. */
  ------------------
  |  Branch (8578:9): [True: 417, False: 0]
  ------------------
 8579|      0|        (tif->tif_flags & TIFF_CHOPPEDUPARRAYS) != 0)
  ------------------
  |  |  156|      0|    0x4000000U /* set when allocChoppedUpStripArrays() has modified strip      \
  ------------------
  |  Branch (8579:9): [True: 0, False: 0]
  ------------------
 8580|    417|        return 1;
 8581|       |
 8582|      0|    if ((tif->tif_flags & TIFF_LAZYSTRILELOAD_ASKED) &&
  ------------------
  |  |  159|      0|    0x8000000U /* set when lazy/ondemand loading of strip/tile                 \
  ------------------
  |  Branch (8582:9): [True: 0, False: 0]
  ------------------
 8583|      0|        !(tif->tif_flags & TIFF_LAZYSTRILELOAD_DONE))
  ------------------
  |  |  152|      0|    0x2000000U /* set when lazy/ondemand loading of strip/tile                 \
  ------------------
  |  Branch (8583:9): [True: 0, False: 0]
  ------------------
 8584|      0|    {
 8585|       |        /* In case of lazy loading, reload completely the arrays */
 8586|      0|        _TIFFfreeExt(tif, td->td_stripoffset_p);
 8587|      0|        _TIFFfreeExt(tif, td->td_stripbytecount_p);
 8588|      0|        td->td_stripoffset_p = NULL;
 8589|      0|        td->td_stripbytecount_p = NULL;
 8590|      0|        td->td_stripoffsetbyteallocsize = 0;
 8591|      0|        tif->tif_flags |= TIFF_LAZYSTRILELOAD_DONE;
  ------------------
  |  |  152|      0|    0x2000000U /* set when lazy/ondemand loading of strip/tile                 \
  ------------------
 8592|      0|    }
 8593|       |
 8594|       |    /* If stripoffset array is already loaded, exit with success */
 8595|      0|    if (td->td_stripoffset_p != NULL)
  ------------------
  |  Branch (8595:9): [True: 0, False: 0]
  ------------------
 8596|      0|        return 1;
 8597|       |
 8598|       |    /* If tdir_count was canceled, then we already got there, but in error */
 8599|      0|    if (td->td_stripoffset_entry.tdir_count == 0)
  ------------------
  |  Branch (8599:9): [True: 0, False: 0]
  ------------------
 8600|      0|        return 0;
 8601|       |
 8602|      0|    if (!TIFFFetchStripThing(tif, &(td->td_stripoffset_entry), td->td_nstrips,
  ------------------
  |  Branch (8602:9): [True: 0, False: 0]
  ------------------
 8603|      0|                             &td->td_stripoffset_p))
 8604|      0|    {
 8605|      0|        return_value = 0;
 8606|      0|    }
 8607|       |
 8608|      0|    if (loadStripByteCount &&
  ------------------
  |  Branch (8608:9): [True: 0, False: 0]
  ------------------
 8609|      0|        !TIFFFetchStripThing(tif, &(td->td_stripbytecount_entry),
  ------------------
  |  Branch (8609:9): [True: 0, False: 0]
  ------------------
 8610|      0|                             td->td_nstrips, &td->td_stripbytecount_p))
 8611|      0|    {
 8612|      0|        return_value = 0;
 8613|      0|    }
 8614|       |
 8615|      0|    _TIFFmemset(&(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
 8616|      0|    _TIFFmemset(&(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
 8617|       |
 8618|       |#ifdef STRIPBYTECOUNTSORTED_UNUSED
 8619|       |    if (tif->tif_dir.td_nstrips > 1 && return_value == 1)
 8620|       |    {
 8621|       |        uint32_t strip;
 8622|       |
 8623|       |        tif->tif_dir.td_stripbytecountsorted = 1;
 8624|       |        for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++)
 8625|       |        {
 8626|       |            if (tif->tif_dir.td_stripoffset_p[strip - 1] >
 8627|       |                tif->tif_dir.td_stripoffset_p[strip])
 8628|       |            {
 8629|       |                tif->tif_dir.td_stripbytecountsorted = 0;
 8630|       |                break;
 8631|       |            }
 8632|       |        }
 8633|       |    }
 8634|       |#endif
 8635|       |
 8636|      0|    return return_value;
 8637|      0|}

TIFFWriteDirectory:
  239|    207|{
  240|    207|    return TIFFWriteDirectorySec(tif, TRUE, TRUE, NULL);
  ------------------
  |  |   74|    207|#define TRUE 1
  ------------------
                  return TIFFWriteDirectorySec(tif, TRUE, TRUE, NULL);
  ------------------
  |  |   74|    207|#define TRUE 1
  ------------------
  241|    207|}
TIFFRewriteDirectory:
  499|    207|{
  500|    207|    return TIFFRewriteDirectorySec(tif, TRUE, TRUE, NULL);
  ------------------
  |  |   74|    207|#define TRUE 1
  ------------------
                  return TIFFRewriteDirectorySec(tif, TRUE, TRUE, NULL);
  ------------------
  |  |   74|    207|#define TRUE 1
  ------------------
  501|    207|}
tif_dirwrite.c:TIFFRewriteDirectorySec:
  317|    207|{
  318|    207|    static const char module[] = "TIFFRewriteDirectory";
  319|       |
  320|       |    /* We don't need to do anything special if it hasn't been written. */
  321|    207|    if (tif->tif_diroff == 0)
  ------------------
  |  Branch (321:9): [True: 207, False: 0]
  ------------------
  322|    207|        return TIFFWriteDirectory(tif);
  323|       |
  324|       |    /*
  325|       |     * Find and zero the pointer to this directory, so that TIFFLinkDirectory
  326|       |     * will cause it to be added after this directories current pre-link.
  327|       |     */
  328|      0|    uint64_t torewritediroff = tif->tif_diroff;
  329|       |
  330|      0|    if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (330:9): [True: 0, False: 0]
  ------------------
  331|      0|    {
  332|      0|        if (tif->tif_header.classic.tiff_diroff == tif->tif_diroff)
  ------------------
  |  Branch (332:13): [True: 0, False: 0]
  ------------------
  333|      0|        {
  334|      0|            tif->tif_header.classic.tiff_diroff = 0;
  335|      0|            tif->tif_diroff = 0;
  336|       |
  337|      0|            TIFFSeekFile(tif, 4, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  338|      0|            if (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff), 4))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (338:17): [True: 0, False: 0]
  ------------------
  339|      0|            {
  340|      0|                TIFFErrorExtR(tif, tif->tif_name, "Error updating TIFF header");
  341|      0|                return (0);
  342|      0|            }
  343|      0|        }
  344|      0|        else if (tif->tif_diroff > 0xFFFFFFFFU)
  ------------------
  |  Branch (344:18): [True: 0, False: 0]
  ------------------
  345|      0|        {
  346|      0|            TIFFErrorExtR(tif, module,
  347|      0|                          "tif->tif_diroff exceeds 32 bit range allowed for "
  348|      0|                          "Classic TIFF");
  349|      0|            return (0);
  350|      0|        }
  351|      0|        else
  352|      0|        {
  353|      0|            uint32_t nextdir;
  354|      0|            tdir_t nextdirnum = 0;
  355|      0|            nextdir = tif->tif_header.classic.tiff_diroff;
  356|      0|            while (1)
  ------------------
  |  Branch (356:20): [True: 0, Folded]
  ------------------
  357|      0|            {
  358|      0|                uint16_t dircount;
  359|      0|                uint32_t nextnextdir;
  360|       |
  361|      0|                if (!_TIFFCheckDirNumberAndOffset(tif, nextdirnum, nextdir))
  ------------------
  |  Branch (361:21): [True: 0, False: 0]
  ------------------
  362|      0|                {
  363|      0|                    TIFFErrorExtR(tif, module, "Error IFD loop detected");
  364|      0|                    return (0);
  365|      0|                }
  366|       |
  367|      0|                if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount, 2))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
                              if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount, 2))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (367:21): [True: 0, False: 0]
  |  Branch (367:46): [True: 0, False: 0]
  ------------------
  368|      0|                {
  369|      0|                    TIFFErrorExtR(tif, module,
  370|      0|                                  "Error fetching directory count");
  371|      0|                    return (0);
  372|      0|                }
  373|      0|                if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (373:21): [True: 0, False: 0]
  ------------------
  374|      0|                    TIFFSwabShort(&dircount);
  375|      0|                (void)TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  376|      0|                if (!ReadOK(tif, &nextnextdir, 4))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (376:21): [True: 0, False: 0]
  ------------------
  377|      0|                {
  378|      0|                    TIFFErrorExtR(tif, module, "Error fetching directory link");
  379|      0|                    return (0);
  380|      0|                }
  381|      0|                if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (381:21): [True: 0, False: 0]
  ------------------
  382|      0|                    TIFFSwabLong(&nextnextdir);
  383|      0|                if (nextnextdir == tif->tif_diroff)
  ------------------
  |  Branch (383:21): [True: 0, False: 0]
  ------------------
  384|      0|                {
  385|      0|                    uint32_t m;
  386|      0|                    m = 0;
  387|      0|                    (void)TIFFSeekFile(tif, nextdir + 2 + dircount * 12U,
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  388|      0|                                       SEEK_SET);
  389|      0|                    if (!WriteOK(tif, &m, 4))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (389:25): [True: 0, False: 0]
  ------------------
  390|      0|                    {
  391|      0|                        TIFFErrorExtR(tif, module,
  392|      0|                                      "Error writing directory link");
  393|      0|                        return (0);
  394|      0|                    }
  395|      0|                    tif->tif_diroff = 0;
  396|       |                    /* Force a full-traversal to reach the zeroed pointer */
  397|      0|                    tif->tif_lastdiroff = 0;
  398|      0|                    break;
  399|      0|                }
  400|      0|                nextdir = nextnextdir;
  401|      0|                nextdirnum++;
  402|      0|            }
  403|      0|        }
  404|       |        /* Remove skipped offset from IFD loop directory list. */
  405|      0|        _TIFFRemoveEntryFromDirectoryListByOffset(tif, torewritediroff);
  406|      0|    }
  407|      0|    else
  408|      0|    {
  409|      0|        if (tif->tif_header.big.tiff_diroff == tif->tif_diroff)
  ------------------
  |  Branch (409:13): [True: 0, False: 0]
  ------------------
  410|      0|        {
  411|      0|            tif->tif_header.big.tiff_diroff = 0;
  412|      0|            tif->tif_diroff = 0;
  413|       |
  414|      0|            TIFFSeekFile(tif, 8, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  415|      0|            if (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff), 8))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (415:17): [True: 0, False: 0]
  ------------------
  416|      0|            {
  417|      0|                TIFFErrorExtR(tif, tif->tif_name, "Error updating TIFF header");
  418|      0|                return (0);
  419|      0|            }
  420|      0|        }
  421|      0|        else
  422|      0|        {
  423|      0|            uint64_t nextdir;
  424|      0|            tdir_t nextdirnum = 0;
  425|      0|            nextdir = tif->tif_header.big.tiff_diroff;
  426|      0|            while (1)
  ------------------
  |  Branch (426:20): [True: 0, Folded]
  ------------------
  427|      0|            {
  428|      0|                uint64_t dircount64;
  429|      0|                uint64_t nextnextdir;
  430|       |
  431|      0|                if (!_TIFFCheckDirNumberAndOffset(tif, nextdirnum, nextdir))
  ------------------
  |  Branch (431:21): [True: 0, False: 0]
  ------------------
  432|      0|                {
  433|      0|                    TIFFErrorExtR(tif, module, "Error IFD loop detected");
  434|      0|                    return (0);
  435|      0|                }
  436|       |
  437|      0|                if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount64, 8))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
                              if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount64, 8))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (437:21): [True: 0, False: 0]
  |  Branch (437:46): [True: 0, False: 0]
  ------------------
  438|      0|                {
  439|      0|                    TIFFErrorExtR(tif, module,
  440|      0|                                  "Error fetching directory count");
  441|      0|                    return (0);
  442|      0|                }
  443|      0|                if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (443:21): [True: 0, False: 0]
  ------------------
  444|      0|                    TIFFSwabLong8(&dircount64);
  445|      0|                if (dircount64 > 0xFFFF)
  ------------------
  |  Branch (445:21): [True: 0, False: 0]
  ------------------
  446|      0|                {
  447|      0|                    TIFFErrorExtR(tif, module,
  448|      0|                                  "Sanity check on tag count failed, likely "
  449|      0|                                  "corrupt TIFF");
  450|      0|                    return (0);
  451|      0|                }
  452|      0|                (void)TIFFSeekFile(tif, nextdir + 8 + dircount64 * 20,
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  453|      0|                                   SEEK_SET);
  454|      0|                if (!ReadOK(tif, &nextnextdir, 8))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (454:21): [True: 0, False: 0]
  ------------------
  455|      0|                {
  456|      0|                    TIFFErrorExtR(tif, module, "Error fetching directory link");
  457|      0|                    return (0);
  458|      0|                }
  459|      0|                if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (459:21): [True: 0, False: 0]
  ------------------
  460|      0|                    TIFFSwabLong8(&nextnextdir);
  461|      0|                if (nextnextdir == tif->tif_diroff)
  ------------------
  |  Branch (461:21): [True: 0, False: 0]
  ------------------
  462|      0|                {
  463|      0|                    uint64_t m;
  464|      0|                    m = 0;
  465|      0|                    (void)TIFFSeekFile(tif, nextdir + 8 + dircount64 * 20,
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  466|      0|                                       SEEK_SET);
  467|      0|                    if (!WriteOK(tif, &m, 8))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (467:25): [True: 0, False: 0]
  ------------------
  468|      0|                    {
  469|      0|                        TIFFErrorExtR(tif, module,
  470|      0|                                      "Error writing directory link");
  471|      0|                        return (0);
  472|      0|                    }
  473|      0|                    tif->tif_diroff = 0;
  474|       |                    /* Force a full-traversal to reach the zeroed pointer */
  475|      0|                    tif->tif_lastdiroff = 0;
  476|      0|                    break;
  477|      0|                }
  478|      0|                nextdir = nextnextdir;
  479|      0|                nextdirnum++;
  480|      0|            }
  481|      0|        }
  482|       |        /* Remove skipped offset from IFD loop directory list. */
  483|      0|        _TIFFRemoveEntryFromDirectoryListByOffset(tif, torewritediroff);
  484|      0|    }
  485|       |
  486|       |    /*
  487|       |     * Now use TIFFWriteDirectorySec() normally.
  488|       |     */
  489|      0|    return TIFFWriteDirectorySec(tif, isimage, imagedone, pdiroff);
  490|      0|} /*-- TIFFRewriteDirectorySec() --*/
tif_dirwrite.c:TIFFWriteDirectorySec:
  505|    207|{
  506|    207|    static const char module[] = "TIFFWriteDirectorySec";
  507|    207|    uint32_t ndir;
  508|    207|    TIFFDirEntry *dir;
  509|    207|    uint32_t dirsize;
  510|    207|    void *dirmem;
  511|    207|    uint32_t m;
  512|    207|    if (tif->tif_mode == O_RDONLY)
  ------------------
  |  Branch (512:9): [True: 0, False: 207]
  ------------------
  513|      0|        return (1);
  514|       |
  515|    207|    _TIFFFillStriles(tif);
  516|       |
  517|       |    /*
  518|       |     * Clear write state so that subsequent images with
  519|       |     * different characteristics get the right buffers
  520|       |     * setup for them.
  521|       |     */
  522|    207|    if (imagedone)
  ------------------
  |  Branch (522:9): [True: 207, False: 0]
  ------------------
  523|    207|    {
  524|    207|        if (tif->tif_flags & TIFF_POSTENCODE)
  ------------------
  |  |  134|    207|#define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
  ------------------
  |  Branch (524:13): [True: 0, False: 207]
  ------------------
  525|      0|        {
  526|      0|            tif->tif_flags &= ~TIFF_POSTENCODE;
  ------------------
  |  |  134|      0|#define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
  ------------------
  527|      0|            if (!(*tif->tif_postencode)(tif))
  ------------------
  |  Branch (527:17): [True: 0, False: 0]
  ------------------
  528|      0|            {
  529|      0|                TIFFErrorExtR(tif, module,
  530|      0|                              "Error post-encoding before directory write");
  531|      0|                return (0);
  532|      0|            }
  533|      0|        }
  534|    207|        (*tif->tif_close)(tif); /* shutdown encoder */
  535|       |        /*
  536|       |         * Flush any data that might have been written
  537|       |         * by the compression close+cleanup routines.  But
  538|       |         * be careful not to write stuff if we didn't add data
  539|       |         * in the previous steps as the "rawcc" data may well be
  540|       |         * a previously read tile/strip in mixed read/write mode.
  541|       |         */
  542|    207|        if (tif->tif_rawcc > 0 && (tif->tif_flags & TIFF_BEENWRITING) != 0)
  ------------------
  |  |  128|      0|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
  |  Branch (542:13): [True: 0, False: 207]
  |  Branch (542:35): [True: 0, False: 0]
  ------------------
  543|      0|        {
  544|      0|            if (!TIFFFlushData1(tif))
  ------------------
  |  Branch (544:17): [True: 0, False: 0]
  ------------------
  545|      0|            {
  546|      0|                TIFFErrorExtR(tif, module,
  547|      0|                              "Error flushing data before directory write");
  548|      0|                return (0);
  549|      0|            }
  550|      0|        }
  551|    207|        if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
  ------------------
  |  |  131|    207|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  |  Branch (551:13): [True: 207, False: 0]
  |  Branch (551:49): [True: 207, False: 0]
  ------------------
  552|    207|        {
  553|    207|            _TIFFfreeExt(tif, tif->tif_rawdata);
  554|    207|            tif->tif_rawdata = NULL;
  555|    207|            tif->tif_rawcp = NULL;
  556|    207|            tif->tif_rawcc = 0;
  557|    207|            tif->tif_rawdatasize = 0;
  558|    207|            tif->tif_rawdataoff = 0;
  559|    207|            tif->tif_rawdataloaded = 0;
  560|    207|        }
  561|    207|        tif->tif_flags &= ~(TIFF_BEENWRITING | TIFF_BUFFERSETUP);
  ------------------
  |  |  128|    207|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
                      tif->tif_flags &= ~(TIFF_BEENWRITING | TIFF_BUFFERSETUP);
  ------------------
  |  |  126|    207|#define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */
  ------------------
  562|    207|    }
  563|       |
  564|    207|    if (TIFFFieldSet(tif, FIELD_COMPRESSION) &&
  ------------------
  |  |  267|    414|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 207, False: 0]
  |  |  ------------------
  ------------------
  565|    207|        (tif->tif_dir.td_compression == COMPRESSION_DEFLATE))
  ------------------
  |  |  205|    207|#define COMPRESSION_DEFLATE 32946   /* Deflate compression, legacy tag */
  ------------------
  |  Branch (565:9): [True: 0, False: 207]
  ------------------
  566|      0|    {
  567|      0|        TIFFWarningExtR(tif, module,
  568|      0|                        "Creating TIFF with legacy Deflate codec identifier, "
  569|      0|                        "COMPRESSION_ADOBE_DEFLATE is more widely supported");
  570|      0|    }
  571|    207|    dir = NULL;
  572|    207|    dirmem = NULL;
  573|    207|    dirsize = 0;
  574|    377|    while (1)
  ------------------
  |  Branch (574:12): [True: 377, Folded]
  ------------------
  575|    377|    {
  576|       |        /* The first loop only determines "ndir" and uses TIFFLinkDirectory() to
  577|       |         * set the offset at which the IFD is to be written to the file.
  578|       |         * The second loop writes IFD entries to the file. */
  579|    377|        ndir = 0;
  580|    377|        if (dir == NULL)
  ------------------
  |  Branch (580:13): [True: 207, False: 170]
  ------------------
  581|    207|            tif->tif_dir.td_dirdatasize_write = 0;
  582|    377|        if (isimage)
  ------------------
  |  Branch (582:13): [True: 377, False: 0]
  ------------------
  583|    377|        {
  584|       |            /*-- Step 1: Process named tags for an image with FIELD bits
  585|       |             *           associated. --*/
  586|    377|            if (TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  587|    377|            {
  588|    377|                if (!TIFFWriteDirectoryTagShortLong(tif, &ndir, dir,
  ------------------
  |  Branch (588:21): [True: 0, False: 377]
  ------------------
  589|    377|                                                    TIFFTAG_IMAGEWIDTH,
  ------------------
  |  |  178|    377|#define TIFFTAG_IMAGEWIDTH 256        /* image width in pixels */
  ------------------
  590|    377|                                                    tif->tif_dir.td_imagewidth))
  591|      0|                    goto bad;
  592|    377|                if (!TIFFWriteDirectoryTagShortLong(
  ------------------
  |  Branch (592:21): [True: 0, False: 377]
  ------------------
  593|    377|                        tif, &ndir, dir, TIFFTAG_IMAGELENGTH,
  ------------------
  |  |  179|    377|#define TIFFTAG_IMAGELENGTH 257       /* image height in pixels */
  ------------------
  594|    377|                        tif->tif_dir.td_imagelength))
  595|      0|                    goto bad;
  596|    377|            }
  597|    377|            if (TIFFFieldSet(tif, FIELD_TILEDIMENSIONS))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  598|      0|            {
  599|      0|                if (!TIFFWriteDirectoryTagShortLong(tif, &ndir, dir,
  ------------------
  |  Branch (599:21): [True: 0, False: 0]
  ------------------
  600|      0|                                                    TIFFTAG_TILEWIDTH,
  ------------------
  |  |  311|      0|#define TIFFTAG_TILEWIDTH 322              /* !tile width in pixels */
  ------------------
  601|      0|                                                    tif->tif_dir.td_tilewidth))
  602|      0|                    goto bad;
  603|      0|                if (!TIFFWriteDirectoryTagShortLong(tif, &ndir, dir,
  ------------------
  |  Branch (603:21): [True: 0, False: 0]
  ------------------
  604|      0|                                                    TIFFTAG_TILELENGTH,
  ------------------
  |  |  312|      0|#define TIFFTAG_TILELENGTH 323             /* !tile height in pixels */
  ------------------
  605|      0|                                                    tif->tif_dir.td_tilelength))
  606|      0|                    goto bad;
  607|      0|            }
  608|    377|            if (TIFFFieldSet(tif, FIELD_RESOLUTION))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  609|      0|            {
  610|      0|                if (!TIFFWriteDirectoryTagRational(
  ------------------
  |  Branch (610:21): [True: 0, False: 0]
  ------------------
  611|      0|                        tif, &ndir, dir, TIFFTAG_XRESOLUTION,
  ------------------
  |  |  262|      0|#define TIFFTAG_XRESOLUTION 282            /* pixels/resolution in x */
  ------------------
  612|      0|                        (double)tif->tif_dir.td_xresolution))
  613|      0|                    goto bad;
  614|      0|                if (!TIFFWriteDirectoryTagRational(
  ------------------
  |  Branch (614:21): [True: 0, False: 0]
  ------------------
  615|      0|                        tif, &ndir, dir, TIFFTAG_YRESOLUTION,
  ------------------
  |  |  263|      0|#define TIFFTAG_YRESOLUTION 283            /* pixels/resolution in y */
  ------------------
  616|      0|                        (double)tif->tif_dir.td_yresolution))
  617|      0|                    goto bad;
  618|      0|            }
  619|    377|            if (TIFFFieldSet(tif, FIELD_POSITION))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  620|      0|            {
  621|      0|                if (!TIFFWriteDirectoryTagRational(
  ------------------
  |  Branch (621:21): [True: 0, False: 0]
  ------------------
  622|      0|                        tif, &ndir, dir, TIFFTAG_XPOSITION,
  ------------------
  |  |  268|      0|#define TIFFTAG_XPOSITION 286              /* x page offset of image lhs */
  ------------------
  623|      0|                        (double)tif->tif_dir.td_xposition))
  624|      0|                    goto bad;
  625|      0|                if (!TIFFWriteDirectoryTagRational(
  ------------------
  |  Branch (625:21): [True: 0, False: 0]
  ------------------
  626|      0|                        tif, &ndir, dir, TIFFTAG_YPOSITION,
  ------------------
  |  |  269|      0|#define TIFFTAG_YPOSITION 287              /* y page offset of image lhs */
  ------------------
  627|      0|                        (double)tif->tif_dir.td_yposition))
  628|      0|                    goto bad;
  629|      0|            }
  630|    377|            if (TIFFFieldSet(tif, FIELD_SUBFILETYPE))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  631|      0|            {
  632|      0|                if (!TIFFWriteDirectoryTagLong(tif, &ndir, dir,
  ------------------
  |  Branch (632:21): [True: 0, False: 0]
  ------------------
  633|      0|                                               TIFFTAG_SUBFILETYPE,
  ------------------
  |  |  170|      0|#define TIFFTAG_SUBFILETYPE 254       /* subfile data descriptor */
  ------------------
  634|      0|                                               tif->tif_dir.td_subfiletype))
  635|      0|                    goto bad;
  636|      0|            }
  637|    377|            if (TIFFFieldSet(tif, FIELD_BITSPERSAMPLE))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  638|    377|            {
  639|    377|                if (!TIFFWriteDirectoryTagShortPerSample(
  ------------------
  |  Branch (639:21): [True: 0, False: 377]
  ------------------
  640|    377|                        tif, &ndir, dir, TIFFTAG_BITSPERSAMPLE,
  ------------------
  |  |  180|    377|#define TIFFTAG_BITSPERSAMPLE 258     /* bits per channel (sample) */
  ------------------
  641|    377|                        tif->tif_dir.td_bitspersample))
  642|      0|                    goto bad;
  643|    377|            }
  644|    377|            if (TIFFFieldSet(tif, FIELD_COMPRESSION))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  645|    377|            {
  646|    377|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (646:21): [True: 0, False: 377]
  ------------------
  647|    377|                                                TIFFTAG_COMPRESSION,
  ------------------
  |  |  181|    377|#define TIFFTAG_COMPRESSION 259       /* data compression technique */
  ------------------
  648|    377|                                                tif->tif_dir.td_compression))
  649|      0|                    goto bad;
  650|    377|            }
  651|    377|            if (TIFFFieldSet(tif, FIELD_PHOTOMETRIC))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  652|    377|            {
  653|    377|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (653:21): [True: 0, False: 377]
  ------------------
  654|    377|                                                TIFFTAG_PHOTOMETRIC,
  ------------------
  |  |  220|    377|#define TIFFTAG_PHOTOMETRIC 262            /* photometric interpretation */
  ------------------
  655|    377|                                                tif->tif_dir.td_photometric))
  656|      0|                    goto bad;
  657|    377|            }
  658|    377|            if (TIFFFieldSet(tif, FIELD_THRESHHOLDING))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  659|      0|            {
  660|      0|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (660:21): [True: 0, False: 0]
  ------------------
  661|      0|                                                TIFFTAG_THRESHHOLDING,
  ------------------
  |  |  234|      0|#define TIFFTAG_THRESHHOLDING 263          /* +thresholding used on data */
  ------------------
  662|      0|                                                tif->tif_dir.td_threshholding))
  663|      0|                    goto bad;
  664|      0|            }
  665|    377|            if (TIFFFieldSet(tif, FIELD_FILLORDER))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  666|      0|            {
  667|      0|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (667:21): [True: 0, False: 0]
  ------------------
  668|      0|                                                TIFFTAG_FILLORDER,
  ------------------
  |  |  240|      0|#define TIFFTAG_FILLORDER 266              /* data order within a byte */
  ------------------
  669|      0|                                                tif->tif_dir.td_fillorder))
  670|      0|                    goto bad;
  671|      0|            }
  672|    377|            if (TIFFFieldSet(tif, FIELD_ORIENTATION))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  673|      0|            {
  674|      0|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (674:21): [True: 0, False: 0]
  ------------------
  675|      0|                                                TIFFTAG_ORIENTATION,
  ------------------
  |  |  248|      0|#define TIFFTAG_ORIENTATION 274            /* +image orientation */
  ------------------
  676|      0|                                                tif->tif_dir.td_orientation))
  677|      0|                    goto bad;
  678|      0|            }
  679|    377|            if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  680|    377|            {
  681|    377|                if (!TIFFWriteDirectoryTagShort(
  ------------------
  |  Branch (681:21): [True: 0, False: 377]
  ------------------
  682|    377|                        tif, &ndir, dir, TIFFTAG_SAMPLESPERPIXEL,
  ------------------
  |  |  257|    377|#define TIFFTAG_SAMPLESPERPIXEL 277        /* samples per pixel */
  ------------------
  683|    377|                        tif->tif_dir.td_samplesperpixel))
  684|      0|                    goto bad;
  685|    377|            }
  686|    377|            if (TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  687|    377|            {
  688|    377|                if (!TIFFWriteDirectoryTagShortLong(
  ------------------
  |  Branch (688:21): [True: 0, False: 377]
  ------------------
  689|    377|                        tif, &ndir, dir, TIFFTAG_ROWSPERSTRIP,
  ------------------
  |  |  258|    377|#define TIFFTAG_ROWSPERSTRIP 278           /* rows per strip of data */
  ------------------
  690|    377|                        tif->tif_dir.td_rowsperstrip))
  691|      0|                    goto bad;
  692|    377|            }
  693|    377|            if (TIFFFieldSet(tif, FIELD_MINSAMPLEVALUE))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  694|      0|            {
  695|      0|                if (!TIFFWriteDirectoryTagShortPerSample(
  ------------------
  |  Branch (695:21): [True: 0, False: 0]
  ------------------
  696|      0|                        tif, &ndir, dir, TIFFTAG_MINSAMPLEVALUE,
  ------------------
  |  |  260|      0|#define TIFFTAG_MINSAMPLEVALUE 280         /* +minimum sample value */
  ------------------
  697|      0|                        tif->tif_dir.td_minsamplevalue))
  698|      0|                    goto bad;
  699|      0|            }
  700|    377|            if (TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  701|      0|            {
  702|      0|                if (!TIFFWriteDirectoryTagShortPerSample(
  ------------------
  |  Branch (702:21): [True: 0, False: 0]
  ------------------
  703|      0|                        tif, &ndir, dir, TIFFTAG_MAXSAMPLEVALUE,
  ------------------
  |  |  261|      0|#define TIFFTAG_MAXSAMPLEVALUE 281         /* +maximum sample value */
  ------------------
  704|      0|                        tif->tif_dir.td_maxsamplevalue))
  705|      0|                    goto bad;
  706|      0|            }
  707|    377|            if (TIFFFieldSet(tif, FIELD_PLANARCONFIG))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 319, False: 58]
  |  |  ------------------
  ------------------
  708|    319|            {
  709|    319|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (709:21): [True: 0, False: 319]
  ------------------
  710|    319|                                                TIFFTAG_PLANARCONFIG,
  ------------------
  |  |  264|    319|#define TIFFTAG_PLANARCONFIG 284           /* storage organization */
  ------------------
  711|    319|                                                tif->tif_dir.td_planarconfig))
  712|      0|                    goto bad;
  713|    319|            }
  714|    377|            if (TIFFFieldSet(tif, FIELD_RESOLUTIONUNIT))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  715|      0|            {
  716|      0|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (716:21): [True: 0, False: 0]
  ------------------
  717|      0|                                                TIFFTAG_RESOLUTIONUNIT,
  ------------------
  |  |  287|      0|#define TIFFTAG_RESOLUTIONUNIT 296         /* units of resolutions */
  ------------------
  718|      0|                                                tif->tif_dir.td_resolutionunit))
  719|      0|                    goto bad;
  720|      0|            }
  721|    377|            if (TIFFFieldSet(tif, FIELD_PAGENUMBER))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 377]
  |  |  ------------------
  ------------------
  722|      0|            {
  723|      0|                if (!TIFFWriteDirectoryTagShortArray(
  ------------------
  |  Branch (723:21): [True: 0, False: 0]
  ------------------
  724|      0|                        tif, &ndir, dir, TIFFTAG_PAGENUMBER, 2,
  ------------------
  |  |  291|      0|#define TIFFTAG_PAGENUMBER 297             /* page numbers of multi-page */
  ------------------
  725|      0|                        &tif->tif_dir.td_pagenumber[0]))
  726|      0|                    goto bad;
  727|      0|            }
  728|    377|            if (TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS))
  ------------------
  |  |  267|    377|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    377|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    377|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 377, False: 0]
  |  |  ------------------
  ------------------
  729|    377|            {
  730|       |                /*  Check td_stripbytecount_p for NULL pointer (bug#749) */
  731|    377|                if (tif->tif_dir.td_stripbytecount_p == NULL)
  ------------------
  |  Branch (731:21): [True: 0, False: 377]
  ------------------
  732|      0|                {
  733|      0|                    TIFFErrorExtR(
  734|      0|                        tif, module,
  735|      0|                        "StripByteCount array is not set, pointer is NULL");
  736|      0|                    goto bad;
  737|      0|                }
  738|    377|                if (!isTiled(tif))
  ------------------
  |  |  282|    377|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    377|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  ------------------
  |  Branch (738:21): [True: 377, False: 0]
  ------------------
  739|    377|                {
  740|    377|                    if (!TIFFWriteDirectoryTagLongLong8Array(
  ------------------
  |  Branch (740:25): [True: 37, False: 340]
  ------------------
  741|    377|                            tif, &ndir, dir, TIFFTAG_STRIPBYTECOUNTS,
  ------------------
  |  |  259|    377|#define TIFFTAG_STRIPBYTECOUNTS 279        /* bytes counts for strips */
  ------------------
  742|    377|                            tif->tif_dir.td_nstrips,
  743|    377|                            tif->tif_dir.td_stripbytecount_p))
  744|     37|                        goto bad;
  745|    377|                }
  746|      0|                else
  747|      0|                {
  748|      0|                    if (!TIFFWriteDirectoryTagLongLong8Array(
  ------------------
  |  Branch (748:25): [True: 0, False: 0]
  ------------------
  749|      0|                            tif, &ndir, dir, TIFFTAG_TILEBYTECOUNTS,
  ------------------
  |  |  314|      0|#define TIFFTAG_TILEBYTECOUNTS 325         /* !byte counts for tiles */
  ------------------
  750|      0|                            tif->tif_dir.td_nstrips,
  751|      0|                            tif->tif_dir.td_stripbytecount_p))
  752|      0|                        goto bad;
  753|      0|                }
  754|    377|            }
  755|    340|            if (TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 340, False: 0]
  |  |  ------------------
  ------------------
  756|    340|            {
  757|       |                /*  Check td_stripoffset_p for NULL pointer (bug#749) */
  758|    340|                if (tif->tif_dir.td_stripoffset_p == NULL)
  ------------------
  |  Branch (758:21): [True: 0, False: 340]
  ------------------
  759|      0|                {
  760|      0|                    TIFFErrorExtR(
  761|      0|                        tif, module,
  762|      0|                        "StripByteOffset array is not set, pointer is NULL");
  763|      0|                    goto bad;
  764|      0|                }
  765|    340|                if (!isTiled(tif))
  ------------------
  |  |  282|    340|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    340|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  ------------------
  |  Branch (765:21): [True: 340, False: 0]
  ------------------
  766|    340|                {
  767|       |                    /* td_stripoffset_p might be NULL in an odd OJPEG case. See
  768|       |                     *  tif_dirread.c around line 3634.
  769|       |                     * XXX: OJPEG hack.
  770|       |                     * If a) compression is OJPEG, b) it's not a tiled TIFF,
  771|       |                     * and c) the number of strips is 1,
  772|       |                     * then we tolerate the absence of stripoffsets tag,
  773|       |                     * because, presumably, all required data is in the
  774|       |                     * JpegInterchangeFormat stream.
  775|       |                     * We can get here when using tiffset on such a file.
  776|       |                     * See http://bugzilla.maptools.org/show_bug.cgi?id=2500
  777|       |                     */
  778|    340|                    if (tif->tif_dir.td_stripoffset_p != NULL &&
  ------------------
  |  Branch (778:25): [True: 340, False: 0]
  ------------------
  779|    340|                        !TIFFWriteDirectoryTagLongLong8Array(
  ------------------
  |  Branch (779:25): [True: 0, False: 340]
  ------------------
  780|    340|                            tif, &ndir, dir, TIFFTAG_STRIPOFFSETS,
  ------------------
  |  |  247|    340|#define TIFFTAG_STRIPOFFSETS 273           /* offsets to data strips */
  ------------------
  781|    340|                            tif->tif_dir.td_nstrips,
  782|    340|                            tif->tif_dir.td_stripoffset_p))
  783|      0|                        goto bad;
  784|    340|                }
  785|      0|                else
  786|      0|                {
  787|      0|                    if (!TIFFWriteDirectoryTagLongLong8Array(
  ------------------
  |  Branch (787:25): [True: 0, False: 0]
  ------------------
  788|      0|                            tif, &ndir, dir, TIFFTAG_TILEOFFSETS,
  ------------------
  |  |  313|      0|#define TIFFTAG_TILEOFFSETS 324            /* !offsets to data tiles */
  ------------------
  789|      0|                            tif->tif_dir.td_nstrips,
  790|      0|                            tif->tif_dir.td_stripoffset_p))
  791|      0|                        goto bad;
  792|      0|                }
  793|    340|            }
  794|    340|            if (TIFFFieldSet(tif, FIELD_COLORMAP))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  795|      0|            {
  796|      0|                if (!TIFFWriteDirectoryTagColormap(tif, &ndir, dir))
  ------------------
  |  Branch (796:21): [True: 0, False: 0]
  ------------------
  797|      0|                    goto bad;
  798|      0|            }
  799|    340|            if (TIFFFieldSet(tif, FIELD_EXTRASAMPLES))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  800|      0|            {
  801|      0|                if (tif->tif_dir.td_extrasamples)
  ------------------
  |  Branch (801:21): [True: 0, False: 0]
  ------------------
  802|      0|                {
  803|      0|                    uint16_t na;
  804|      0|                    uint16_t *nb;
  805|      0|                    TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &na, &nb);
  ------------------
  |  |  329|      0|#define TIFFTAG_EXTRASAMPLES 338           /* !info about extra samples */
  ------------------
  806|      0|                    if (!TIFFWriteDirectoryTagShortArray(
  ------------------
  |  Branch (806:25): [True: 0, False: 0]
  ------------------
  807|      0|                            tif, &ndir, dir, TIFFTAG_EXTRASAMPLES, na, nb))
  ------------------
  |  |  329|      0|#define TIFFTAG_EXTRASAMPLES 338           /* !info about extra samples */
  ------------------
  808|      0|                        goto bad;
  809|      0|                }
  810|      0|            }
  811|    340|            if (TIFFFieldSet(tif, FIELD_SAMPLEFORMAT))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  812|      0|            {
  813|      0|                if (!TIFFWriteDirectoryTagShortPerSample(
  ------------------
  |  Branch (813:21): [True: 0, False: 0]
  ------------------
  814|      0|                        tif, &ndir, dir, TIFFTAG_SAMPLEFORMAT,
  ------------------
  |  |  333|      0|#define TIFFTAG_SAMPLEFORMAT 339           /* !data sample format */
  ------------------
  815|      0|                        tif->tif_dir.td_sampleformat))
  816|      0|                    goto bad;
  817|      0|            }
  818|    340|            if (TIFFFieldSet(tif, FIELD_SMINSAMPLEVALUE))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  819|      0|            {
  820|      0|                if (!TIFFWriteDirectoryTagSampleformatArray(
  ------------------
  |  Branch (820:21): [True: 0, False: 0]
  ------------------
  821|      0|                        tif, &ndir, dir, TIFFTAG_SMINSAMPLEVALUE,
  ------------------
  |  |  340|      0|#define TIFFTAG_SMINSAMPLEVALUE 340        /* !variable MinSampleValue */
  ------------------
  822|      0|                        tif->tif_dir.td_samplesperpixel,
  823|      0|                        tif->tif_dir.td_sminsamplevalue))
  824|      0|                    goto bad;
  825|      0|            }
  826|    340|            if (TIFFFieldSet(tif, FIELD_SMAXSAMPLEVALUE))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  827|      0|            {
  828|      0|                if (!TIFFWriteDirectoryTagSampleformatArray(
  ------------------
  |  Branch (828:21): [True: 0, False: 0]
  ------------------
  829|      0|                        tif, &ndir, dir, TIFFTAG_SMAXSAMPLEVALUE,
  ------------------
  |  |  341|      0|#define TIFFTAG_SMAXSAMPLEVALUE 341        /* !variable MaxSampleValue */
  ------------------
  830|      0|                        tif->tif_dir.td_samplesperpixel,
  831|      0|                        tif->tif_dir.td_smaxsamplevalue))
  832|      0|                    goto bad;
  833|      0|            }
  834|    340|            if (TIFFFieldSet(tif, FIELD_IMAGEDEPTH))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  835|      0|            {
  836|      0|                if (!TIFFWriteDirectoryTagLong(tif, &ndir, dir,
  ------------------
  |  Branch (836:21): [True: 0, False: 0]
  ------------------
  837|      0|                                               TIFFTAG_IMAGEDEPTH,
  ------------------
  |  |  407|      0|#define TIFFTAG_IMAGEDEPTH 32997 /* z depth of image */
  ------------------
  838|      0|                                               tif->tif_dir.td_imagedepth))
  839|      0|                    goto bad;
  840|      0|            }
  841|    340|            if (TIFFFieldSet(tif, FIELD_TILEDEPTH))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  842|      0|            {
  843|      0|                if (!TIFFWriteDirectoryTagLong(tif, &ndir, dir,
  ------------------
  |  Branch (843:21): [True: 0, False: 0]
  ------------------
  844|      0|                                               TIFFTAG_TILEDEPTH,
  ------------------
  |  |  408|      0|#define TIFFTAG_TILEDEPTH 32998  /* z depth/data tile */
  ------------------
  845|      0|                                               tif->tif_dir.td_tiledepth))
  846|      0|                    goto bad;
  847|      0|            }
  848|    340|            if (TIFFFieldSet(tif, FIELD_HALFTONEHINTS))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  849|      0|            {
  850|      0|                if (!TIFFWriteDirectoryTagShortArray(
  ------------------
  |  Branch (850:21): [True: 0, False: 0]
  ------------------
  851|      0|                        tif, &ndir, dir, TIFFTAG_HALFTONEHINTS, 2,
  ------------------
  |  |  310|      0|#define TIFFTAG_HALFTONEHINTS 321          /* !highlight+shadow info */
  ------------------
  852|      0|                        &tif->tif_dir.td_halftonehints[0]))
  853|      0|                    goto bad;
  854|      0|            }
  855|    340|            if (TIFFFieldSet(tif, FIELD_YCBCRSUBSAMPLING))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  856|      0|            {
  857|      0|                if (!TIFFWriteDirectoryTagShortArray(
  ------------------
  |  Branch (857:21): [True: 0, False: 0]
  ------------------
  858|      0|                        tif, &ndir, dir, TIFFTAG_YCBCRSUBSAMPLING, 2,
  ------------------
  |  |  388|      0|#define TIFFTAG_YCBCRSUBSAMPLING 530       /* !YCbCr subsampling factors */
  ------------------
  859|      0|                        &tif->tif_dir.td_ycbcrsubsampling[0]))
  860|      0|                    goto bad;
  861|      0|            }
  862|    340|            if (TIFFFieldSet(tif, FIELD_YCBCRPOSITIONING))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  863|      0|            {
  864|      0|                if (!TIFFWriteDirectoryTagShort(
  ------------------
  |  Branch (864:21): [True: 0, False: 0]
  ------------------
  865|      0|                        tif, &ndir, dir, TIFFTAG_YCBCRPOSITIONING,
  ------------------
  |  |  389|      0|#define TIFFTAG_YCBCRPOSITIONING 531       /* !subsample positioning */
  ------------------
  866|      0|                        tif->tif_dir.td_ycbcrpositioning))
  867|      0|                    goto bad;
  868|      0|            }
  869|    340|            if (TIFFFieldSet(tif, FIELD_REFBLACKWHITE))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  870|      0|            {
  871|      0|                if (!TIFFWriteDirectoryTagRationalArray(
  ------------------
  |  Branch (871:21): [True: 0, False: 0]
  ------------------
  872|      0|                        tif, &ndir, dir, TIFFTAG_REFERENCEBLACKWHITE, 6,
  ------------------
  |  |  392|      0|#define TIFFTAG_REFERENCEBLACKWHITE 532    /* !colorimetry info */
  ------------------
  873|      0|                        tif->tif_dir.td_refblackwhite))
  874|      0|                    goto bad;
  875|      0|            }
  876|    340|            if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  877|      0|            {
  878|      0|                if (!TIFFWriteDirectoryTagTransferfunction(tif, &ndir, dir))
  ------------------
  |  Branch (878:21): [True: 0, False: 0]
  ------------------
  879|      0|                    goto bad;
  880|      0|            }
  881|    340|            if (TIFFFieldSet(tif, FIELD_INKNAMES))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  882|      0|            {
  883|      0|                if (!TIFFWriteDirectoryTagAscii(
  ------------------
  |  Branch (883:21): [True: 0, False: 0]
  ------------------
  884|      0|                        tif, &ndir, dir, TIFFTAG_INKNAMES,
  ------------------
  |  |  325|      0|#define TIFFTAG_INKNAMES 333               /* !ascii names of inks */
  ------------------
  885|      0|                        (uint32_t)tif->tif_dir.td_inknameslen,
  886|      0|                        tif->tif_dir.td_inknames))
  887|      0|                    goto bad;
  888|      0|            }
  889|    340|            if (TIFFFieldSet(tif, FIELD_NUMBEROFINKS))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  890|      0|            {
  891|      0|                if (!TIFFWriteDirectoryTagShort(tif, &ndir, dir,
  ------------------
  |  Branch (891:21): [True: 0, False: 0]
  ------------------
  892|      0|                                                TIFFTAG_NUMBEROFINKS,
  ------------------
  |  |  326|      0|#define TIFFTAG_NUMBEROFINKS 334           /* !number of inks */
  ------------------
  893|      0|                                                tif->tif_dir.td_numberofinks))
  894|      0|                    goto bad;
  895|      0|            }
  896|    340|            if (TIFFFieldSet(tif, FIELD_SUBIFD))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    340|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    340|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 340]
  |  |  ------------------
  ------------------
  897|      0|            {
  898|      0|                if (!TIFFWriteDirectoryTagSubifd(tif, &ndir, dir))
  ------------------
  |  Branch (898:21): [True: 0, False: 0]
  ------------------
  899|      0|                    goto bad;
  900|      0|            }
  901|       |            /*-- Step 2: Process named tags for an image with FIELD bits
  902|       |                         added by a codec.
  903|       |                         Attention: There is only code for some field_types,
  904|       |                         which are actually used by current codecs. --*/
  905|    340|            {
  906|    340|                uint32_t n;
  907|  52.3k|                for (n = 0; n < tif->tif_nfields; n++)
  ------------------
  |  Branch (907:29): [True: 52.0k, False: 340]
  ------------------
  908|  52.0k|                {
  909|  52.0k|                    const TIFFField *o;
  910|  52.0k|                    o = tif->tif_fields[n];
  911|  52.0k|                    if ((o->field_bit >= FIELD_CODEC) &&
  ------------------
  |  |  251|  52.0k|#define FIELD_CODEC 66 /* base of codec-private tags */
  ------------------
  |  Branch (911:25): [True: 0, False: 52.0k]
  ------------------
  912|      0|                        (TIFFFieldSet(tif, o->field_bit)))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  |  Branch (912:25): [True: 0, False: 0]
  ------------------
  913|      0|                    {
  914|       |                        /* The field table keeps the tags of a codec that was
  915|       |                         * previously set on this directory, and codecs share
  916|       |                         * the field bits from FIELD_CODEC on. Such a tag looks
  917|       |                         * set, but TIFFGetField() fails and leaves its
  918|       |                         * arguments uninitialized: skip it. */
  919|      0|                        switch (o->set_get_field_type)
  920|      0|                        {
  921|      0|                            case TIFF_SETGET_ASCII:
  ------------------
  |  Branch (921:29): [True: 0, False: 0]
  ------------------
  922|      0|                            {
  923|      0|                                uint32_t pa;
  924|      0|                                char *pb;
  925|      0|                                assert(o->field_type == TIFF_ASCII);
  ------------------
  |  Branch (925:33): [True: 0, False: 0]
  |  Branch (925:33): [True: 0, False: 0]
  ------------------
  926|      0|                                assert(o->field_readcount == TIFF_VARIABLE);
  ------------------
  |  Branch (926:33): [True: 0, False: 0]
  |  Branch (926:33): [True: 0, False: 0]
  ------------------
  927|      0|                                assert(o->field_passcount == 0);
  ------------------
  |  Branch (927:33): [True: 0, False: 0]
  |  Branch (927:33): [True: 0, False: 0]
  ------------------
  928|      0|                                if (!TIFFGetField(tif, o->field_tag, &pb))
  ------------------
  |  Branch (928:37): [True: 0, False: 0]
  ------------------
  929|      0|                                    break;
  930|      0|                                pa = (uint32_t)(strlen(pb) + 1);
  931|      0|                                if (!TIFFWriteDirectoryTagAscii(
  ------------------
  |  Branch (931:37): [True: 0, False: 0]
  ------------------
  932|      0|                                        tif, &ndir, dir, (uint16_t)o->field_tag,
  933|      0|                                        pa, pb))
  934|      0|                                    goto bad;
  935|      0|                            }
  936|      0|                            break;
  937|      0|                            case TIFF_SETGET_UINT16:
  ------------------
  |  Branch (937:29): [True: 0, False: 0]
  ------------------
  938|      0|                            {
  939|      0|                                uint16_t p;
  940|      0|                                assert(o->field_type == TIFF_SHORT);
  ------------------
  |  Branch (940:33): [True: 0, False: 0]
  |  Branch (940:33): [True: 0, False: 0]
  ------------------
  941|      0|                                assert(o->field_readcount == 1);
  ------------------
  |  Branch (941:33): [True: 0, False: 0]
  |  Branch (941:33): [True: 0, False: 0]
  ------------------
  942|      0|                                assert(o->field_passcount == 0);
  ------------------
  |  Branch (942:33): [True: 0, False: 0]
  |  Branch (942:33): [True: 0, False: 0]
  ------------------
  943|      0|                                if (!TIFFGetField(tif, o->field_tag, &p))
  ------------------
  |  Branch (943:37): [True: 0, False: 0]
  ------------------
  944|      0|                                    break;
  945|      0|                                if (!TIFFWriteDirectoryTagShort(
  ------------------
  |  Branch (945:37): [True: 0, False: 0]
  ------------------
  946|      0|                                        tif, &ndir, dir, (uint16_t)o->field_tag,
  947|      0|                                        p))
  948|      0|                                    goto bad;
  949|      0|                            }
  950|      0|                            break;
  951|      0|                            case TIFF_SETGET_UINT32:
  ------------------
  |  Branch (951:29): [True: 0, False: 0]
  ------------------
  952|      0|                            {
  953|      0|                                uint32_t p;
  954|      0|                                assert(o->field_type == TIFF_LONG);
  ------------------
  |  Branch (954:33): [True: 0, False: 0]
  |  Branch (954:33): [True: 0, False: 0]
  ------------------
  955|      0|                                assert(o->field_readcount == 1);
  ------------------
  |  Branch (955:33): [True: 0, False: 0]
  |  Branch (955:33): [True: 0, False: 0]
  ------------------
  956|      0|                                assert(o->field_passcount == 0);
  ------------------
  |  Branch (956:33): [True: 0, False: 0]
  |  Branch (956:33): [True: 0, False: 0]
  ------------------
  957|      0|                                if (!TIFFGetField(tif, o->field_tag, &p))
  ------------------
  |  Branch (957:37): [True: 0, False: 0]
  ------------------
  958|      0|                                    break;
  959|      0|                                if (!TIFFWriteDirectoryTagLong(
  ------------------
  |  Branch (959:37): [True: 0, False: 0]
  ------------------
  960|      0|                                        tif, &ndir, dir, (uint16_t)o->field_tag,
  961|      0|                                        p))
  962|      0|                                    goto bad;
  963|      0|                            }
  964|      0|                            break;
  965|      0|                            case TIFF_SETGET_C32_UINT8:
  ------------------
  |  Branch (965:29): [True: 0, False: 0]
  ------------------
  966|      0|                            {
  967|      0|                                uint32_t pa;
  968|      0|                                void *pb;
  969|      0|                                assert(o->field_type == TIFF_UNDEFINED);
  ------------------
  |  Branch (969:33): [True: 0, False: 0]
  |  Branch (969:33): [True: 0, False: 0]
  ------------------
  970|      0|                                assert(o->field_readcount == TIFF_VARIABLE2);
  ------------------
  |  Branch (970:33): [True: 0, False: 0]
  |  Branch (970:33): [True: 0, False: 0]
  ------------------
  971|      0|                                assert(o->field_passcount == 1);
  ------------------
  |  Branch (971:33): [True: 0, False: 0]
  |  Branch (971:33): [True: 0, False: 0]
  ------------------
  972|      0|                                if (!TIFFGetField(tif, o->field_tag, &pa, &pb))
  ------------------
  |  Branch (972:37): [True: 0, False: 0]
  ------------------
  973|      0|                                    break;
  974|      0|                                if (!TIFFWriteDirectoryTagUndefinedArray(
  ------------------
  |  Branch (974:37): [True: 0, False: 0]
  ------------------
  975|      0|                                        tif, &ndir, dir, (uint16_t)o->field_tag,
  976|      0|                                        pa, (uint8_t *)pb))
  977|      0|                                    goto bad;
  978|      0|                            }
  979|      0|                            break;
  980|      0|                            case TIFF_SETGET_UNDEFINED:
  ------------------
  |  Branch (980:29): [True: 0, False: 0]
  ------------------
  981|      0|                            case TIFF_SETGET_SINT8:
  ------------------
  |  Branch (981:29): [True: 0, False: 0]
  ------------------
  982|      0|                            case TIFF_SETGET_SINT16:
  ------------------
  |  Branch (982:29): [True: 0, False: 0]
  ------------------
  983|      0|                            case TIFF_SETGET_SINT32:
  ------------------
  |  Branch (983:29): [True: 0, False: 0]
  ------------------
  984|      0|                            case TIFF_SETGET_UINT64:
  ------------------
  |  Branch (984:29): [True: 0, False: 0]
  ------------------
  985|      0|                            case TIFF_SETGET_SINT64:
  ------------------
  |  Branch (985:29): [True: 0, False: 0]
  ------------------
  986|      0|                            case TIFF_SETGET_FLOAT:
  ------------------
  |  Branch (986:29): [True: 0, False: 0]
  ------------------
  987|      0|                            case TIFF_SETGET_DOUBLE:
  ------------------
  |  Branch (987:29): [True: 0, False: 0]
  ------------------
  988|      0|                            case TIFF_SETGET_IFD8:
  ------------------
  |  Branch (988:29): [True: 0, False: 0]
  ------------------
  989|      0|                            case TIFF_SETGET_INT:
  ------------------
  |  Branch (989:29): [True: 0, False: 0]
  ------------------
  990|      0|                            case TIFF_SETGET_UINT16_PAIR:
  ------------------
  |  Branch (990:29): [True: 0, False: 0]
  ------------------
  991|      0|                            case TIFF_SETGET_C0_ASCII:
  ------------------
  |  Branch (991:29): [True: 0, False: 0]
  ------------------
  992|      0|                            case TIFF_SETGET_C0_UINT8:
  ------------------
  |  Branch (992:29): [True: 0, False: 0]
  ------------------
  993|      0|                            case TIFF_SETGET_C0_SINT8:
  ------------------
  |  Branch (993:29): [True: 0, False: 0]
  ------------------
  994|      0|                            case TIFF_SETGET_C0_UINT16:
  ------------------
  |  Branch (994:29): [True: 0, False: 0]
  ------------------
  995|      0|                            case TIFF_SETGET_C0_SINT16:
  ------------------
  |  Branch (995:29): [True: 0, False: 0]
  ------------------
  996|      0|                            case TIFF_SETGET_C0_UINT32:
  ------------------
  |  Branch (996:29): [True: 0, False: 0]
  ------------------
  997|      0|                            case TIFF_SETGET_C0_SINT32:
  ------------------
  |  Branch (997:29): [True: 0, False: 0]
  ------------------
  998|      0|                            case TIFF_SETGET_C0_UINT64:
  ------------------
  |  Branch (998:29): [True: 0, False: 0]
  ------------------
  999|      0|                            case TIFF_SETGET_C0_SINT64:
  ------------------
  |  Branch (999:29): [True: 0, False: 0]
  ------------------
 1000|      0|                            case TIFF_SETGET_C0_FLOAT:
  ------------------
  |  Branch (1000:29): [True: 0, False: 0]
  ------------------
 1001|      0|                            case TIFF_SETGET_C0_DOUBLE:
  ------------------
  |  Branch (1001:29): [True: 0, False: 0]
  ------------------
 1002|      0|                            case TIFF_SETGET_C0_IFD8:
  ------------------
  |  Branch (1002:29): [True: 0, False: 0]
  ------------------
 1003|      0|                            case TIFF_SETGET_C16_ASCII:
  ------------------
  |  Branch (1003:29): [True: 0, False: 0]
  ------------------
 1004|      0|                            case TIFF_SETGET_C16_UINT8:
  ------------------
  |  Branch (1004:29): [True: 0, False: 0]
  ------------------
 1005|      0|                            case TIFF_SETGET_C16_SINT8:
  ------------------
  |  Branch (1005:29): [True: 0, False: 0]
  ------------------
 1006|      0|                            case TIFF_SETGET_C16_UINT16:
  ------------------
  |  Branch (1006:29): [True: 0, False: 0]
  ------------------
 1007|      0|                            case TIFF_SETGET_C16_SINT16:
  ------------------
  |  Branch (1007:29): [True: 0, False: 0]
  ------------------
 1008|      0|                            case TIFF_SETGET_C16_UINT32:
  ------------------
  |  Branch (1008:29): [True: 0, False: 0]
  ------------------
 1009|      0|                            case TIFF_SETGET_C16_SINT32:
  ------------------
  |  Branch (1009:29): [True: 0, False: 0]
  ------------------
 1010|      0|                            case TIFF_SETGET_C16_UINT64:
  ------------------
  |  Branch (1010:29): [True: 0, False: 0]
  ------------------
 1011|      0|                            case TIFF_SETGET_C16_SINT64:
  ------------------
  |  Branch (1011:29): [True: 0, False: 0]
  ------------------
 1012|      0|                            case TIFF_SETGET_C16_FLOAT:
  ------------------
  |  Branch (1012:29): [True: 0, False: 0]
  ------------------
 1013|      0|                            case TIFF_SETGET_C16_DOUBLE:
  ------------------
  |  Branch (1013:29): [True: 0, False: 0]
  ------------------
 1014|      0|                            case TIFF_SETGET_C16_IFD8:
  ------------------
  |  Branch (1014:29): [True: 0, False: 0]
  ------------------
 1015|      0|                            case TIFF_SETGET_C32_ASCII:
  ------------------
  |  Branch (1015:29): [True: 0, False: 0]
  ------------------
 1016|      0|                            case TIFF_SETGET_C32_SINT8:
  ------------------
  |  Branch (1016:29): [True: 0, False: 0]
  ------------------
 1017|      0|                            case TIFF_SETGET_C32_UINT16:
  ------------------
  |  Branch (1017:29): [True: 0, False: 0]
  ------------------
 1018|      0|                            case TIFF_SETGET_C32_SINT16:
  ------------------
  |  Branch (1018:29): [True: 0, False: 0]
  ------------------
 1019|      0|                            case TIFF_SETGET_C32_UINT32:
  ------------------
  |  Branch (1019:29): [True: 0, False: 0]
  ------------------
 1020|      0|                            case TIFF_SETGET_C32_SINT32:
  ------------------
  |  Branch (1020:29): [True: 0, False: 0]
  ------------------
 1021|      0|                            case TIFF_SETGET_C32_UINT64:
  ------------------
  |  Branch (1021:29): [True: 0, False: 0]
  ------------------
 1022|      0|                            case TIFF_SETGET_C32_SINT64:
  ------------------
  |  Branch (1022:29): [True: 0, False: 0]
  ------------------
 1023|      0|                            case TIFF_SETGET_C32_FLOAT:
  ------------------
  |  Branch (1023:29): [True: 0, False: 0]
  ------------------
 1024|      0|                            case TIFF_SETGET_C32_DOUBLE:
  ------------------
  |  Branch (1024:29): [True: 0, False: 0]
  ------------------
 1025|      0|                            case TIFF_SETGET_C32_IFD8:
  ------------------
  |  Branch (1025:29): [True: 0, False: 0]
  ------------------
 1026|      0|                            case TIFF_SETGET_UINT8:
  ------------------
  |  Branch (1026:29): [True: 0, False: 0]
  ------------------
 1027|      0|                            case TIFF_SETGET_OTHER:
  ------------------
  |  Branch (1027:29): [True: 0, False: 0]
  ------------------
 1028|      0|                            default:
  ------------------
  |  Branch (1028:29): [True: 0, False: 0]
  ------------------
 1029|      0|                                TIFFErrorExtR(
 1030|      0|                                    tif, module,
 1031|      0|                                    "Cannot write tag %" PRIu32 " (%s)",
 1032|      0|                                    TIFFFieldTag(o),
 1033|      0|                                    o->field_name ? o->field_name : "unknown");
  ------------------
  |  Branch (1033:37): [True: 0, False: 0]
  ------------------
 1034|      0|                                goto bad;
 1035|      0|                        }
 1036|      0|                    }
 1037|  52.0k|                }
 1038|    340|            }
 1039|    340|        }
 1040|       |        /*-- Step 3: Process custom tags without FIELD bit for an image
 1041|       |         *           or for custom IFDs (e.g. EXIF) with !isimage. --*/
 1042|    340|        for (m = 0; m < (uint32_t)(tif->tif_dir.td_customValueCount); m++)
  ------------------
  |  Branch (1042:21): [True: 0, False: 340]
  ------------------
 1043|      0|        {
 1044|      0|            uint16_t tag =
 1045|      0|                (uint16_t)tif->tif_dir.td_customValues[m].info->field_tag;
 1046|      0|            uint32_t count = (uint32_t)tif->tif_dir.td_customValues[m].count;
 1047|      0|            switch (tif->tif_dir.td_customValues[m].info->field_type)
 1048|      0|            {
 1049|      0|                case TIFF_ASCII:
  ------------------
  |  Branch (1049:17): [True: 0, False: 0]
  ------------------
 1050|      0|                    if (!TIFFWriteDirectoryTagAscii(
  ------------------
  |  Branch (1050:25): [True: 0, False: 0]
  ------------------
 1051|      0|                            tif, &ndir, dir, tag, count,
 1052|      0|                            (char *)tif->tif_dir.td_customValues[m].value))
 1053|      0|                        goto bad;
 1054|      0|                    break;
 1055|      0|                case TIFF_UNDEFINED:
  ------------------
  |  Branch (1055:17): [True: 0, False: 0]
  ------------------
 1056|      0|                    if (!TIFFWriteDirectoryTagUndefinedArray(
  ------------------
  |  Branch (1056:25): [True: 0, False: 0]
  ------------------
 1057|      0|                            tif, &ndir, dir, tag, count,
 1058|      0|                            (uint8_t *)tif->tif_dir.td_customValues[m].value))
 1059|      0|                        goto bad;
 1060|      0|                    break;
 1061|      0|                case TIFF_BYTE:
  ------------------
  |  Branch (1061:17): [True: 0, False: 0]
  ------------------
 1062|      0|                    if (!TIFFWriteDirectoryTagByteArray(
  ------------------
  |  Branch (1062:25): [True: 0, False: 0]
  ------------------
 1063|      0|                            tif, &ndir, dir, tag, count,
 1064|      0|                            (uint8_t *)tif->tif_dir.td_customValues[m].value))
 1065|      0|                        goto bad;
 1066|      0|                    break;
 1067|      0|                case TIFF_SBYTE:
  ------------------
  |  Branch (1067:17): [True: 0, False: 0]
  ------------------
 1068|      0|                    if (!TIFFWriteDirectoryTagSbyteArray(
  ------------------
  |  Branch (1068:25): [True: 0, False: 0]
  ------------------
 1069|      0|                            tif, &ndir, dir, tag, count,
 1070|      0|                            (int8_t *)tif->tif_dir.td_customValues[m].value))
 1071|      0|                        goto bad;
 1072|      0|                    break;
 1073|      0|                case TIFF_SHORT:
  ------------------
  |  Branch (1073:17): [True: 0, False: 0]
  ------------------
 1074|      0|                    if (!TIFFWriteDirectoryTagShortArray(
  ------------------
  |  Branch (1074:25): [True: 0, False: 0]
  ------------------
 1075|      0|                            tif, &ndir, dir, tag, count,
 1076|      0|                            (uint16_t *)tif->tif_dir.td_customValues[m].value))
 1077|      0|                        goto bad;
 1078|      0|                    break;
 1079|      0|                case TIFF_SSHORT:
  ------------------
  |  Branch (1079:17): [True: 0, False: 0]
  ------------------
 1080|      0|                    if (!TIFFWriteDirectoryTagSshortArray(
  ------------------
  |  Branch (1080:25): [True: 0, False: 0]
  ------------------
 1081|      0|                            tif, &ndir, dir, tag, count,
 1082|      0|                            (int16_t *)tif->tif_dir.td_customValues[m].value))
 1083|      0|                        goto bad;
 1084|      0|                    break;
 1085|      0|                case TIFF_LONG:
  ------------------
  |  Branch (1085:17): [True: 0, False: 0]
  ------------------
 1086|      0|                    if (!TIFFWriteDirectoryTagLongArray(
  ------------------
  |  Branch (1086:25): [True: 0, False: 0]
  ------------------
 1087|      0|                            tif, &ndir, dir, tag, count,
 1088|      0|                            (uint32_t *)tif->tif_dir.td_customValues[m].value))
 1089|      0|                        goto bad;
 1090|      0|                    break;
 1091|      0|                case TIFF_SLONG:
  ------------------
  |  Branch (1091:17): [True: 0, False: 0]
  ------------------
 1092|      0|                    if (!TIFFWriteDirectoryTagSlongArray(
  ------------------
  |  Branch (1092:25): [True: 0, False: 0]
  ------------------
 1093|      0|                            tif, &ndir, dir, tag, count,
 1094|      0|                            (int32_t *)tif->tif_dir.td_customValues[m].value))
 1095|      0|                        goto bad;
 1096|      0|                    break;
 1097|      0|                case TIFF_LONG8:
  ------------------
  |  Branch (1097:17): [True: 0, False: 0]
  ------------------
 1098|      0|                    if (!TIFFWriteDirectoryTagLong8Array(
  ------------------
  |  Branch (1098:25): [True: 0, False: 0]
  ------------------
 1099|      0|                            tif, &ndir, dir, tag, count,
 1100|      0|                            (uint64_t *)tif->tif_dir.td_customValues[m].value))
 1101|      0|                        goto bad;
 1102|      0|                    break;
 1103|      0|                case TIFF_SLONG8:
  ------------------
  |  Branch (1103:17): [True: 0, False: 0]
  ------------------
 1104|      0|                    if (!TIFFWriteDirectoryTagSlong8Array(
  ------------------
  |  Branch (1104:25): [True: 0, False: 0]
  ------------------
 1105|      0|                            tif, &ndir, dir, tag, count,
 1106|      0|                            (int64_t *)tif->tif_dir.td_customValues[m].value))
 1107|      0|                        goto bad;
 1108|      0|                    break;
 1109|      0|                case TIFF_RATIONAL:
  ------------------
  |  Branch (1109:17): [True: 0, False: 0]
  ------------------
 1110|      0|                {
 1111|       |                    /*-- Rational2Double: For Rationals evaluate
 1112|       |                     * "set_get_field_type" to determine internal storage size.
 1113|       |                     */
 1114|      0|                    int tv_size;
 1115|      0|                    tv_size = TIFFFieldSetGetSize(
 1116|      0|                        tif->tif_dir.td_customValues[m].info);
 1117|      0|                    if (tv_size == 8)
  ------------------
  |  Branch (1117:25): [True: 0, False: 0]
  ------------------
 1118|      0|                    {
 1119|      0|                        if (!TIFFWriteDirectoryTagRationalDoubleArray(
  ------------------
  |  Branch (1119:29): [True: 0, False: 0]
  ------------------
 1120|      0|                                tif, &ndir, dir, tag, count,
 1121|      0|                                (double *)tif->tif_dir.td_customValues[m]
 1122|      0|                                    .value))
 1123|      0|                            goto bad;
 1124|      0|                    }
 1125|      0|                    else
 1126|      0|                    {
 1127|       |                        /*-- default should be tv_size == 4 */
 1128|      0|                        if (!TIFFWriteDirectoryTagRationalArray(
  ------------------
  |  Branch (1128:29): [True: 0, False: 0]
  ------------------
 1129|      0|                                tif, &ndir, dir, tag, count,
 1130|      0|                                (float *)tif->tif_dir.td_customValues[m].value))
 1131|      0|                            goto bad;
 1132|       |                        /*-- ToDo: After Testing, this should be removed and
 1133|       |                         * tv_size==4 should be set as default. */
 1134|      0|                        if (tv_size != 4)
  ------------------
  |  Branch (1134:29): [True: 0, False: 0]
  ------------------
 1135|      0|                        {
 1136|      0|                            TIFFErrorExtR(
 1137|      0|                                tif, "TIFFLib: _TIFFWriteDirectorySec()",
 1138|      0|                                "Rational2Double: .set_get_field_type is "
 1139|      0|                                "not 4 but %d",
 1140|      0|                                tv_size);
 1141|      0|                        }
 1142|      0|                    }
 1143|      0|                }
 1144|      0|                break;
 1145|      0|                case TIFF_SRATIONAL:
  ------------------
  |  Branch (1145:17): [True: 0, False: 0]
  ------------------
 1146|      0|                {
 1147|       |                    /*-- Rational2Double: For Rationals evaluate
 1148|       |                     * "set_get_field_type" to determine internal storage size.
 1149|       |                     */
 1150|      0|                    int tv_size;
 1151|      0|                    tv_size = TIFFFieldSetGetSize(
 1152|      0|                        tif->tif_dir.td_customValues[m].info);
 1153|      0|                    if (tv_size == 8)
  ------------------
  |  Branch (1153:25): [True: 0, False: 0]
  ------------------
 1154|      0|                    {
 1155|      0|                        if (!TIFFWriteDirectoryTagSrationalDoubleArray(
  ------------------
  |  Branch (1155:29): [True: 0, False: 0]
  ------------------
 1156|      0|                                tif, &ndir, dir, tag, count,
 1157|      0|                                (double *)tif->tif_dir.td_customValues[m]
 1158|      0|                                    .value))
 1159|      0|                            goto bad;
 1160|      0|                    }
 1161|      0|                    else
 1162|      0|                    {
 1163|       |                        /*-- default should be tv_size == 4 */
 1164|      0|                        if (!TIFFWriteDirectoryTagSrationalArray(
  ------------------
  |  Branch (1164:29): [True: 0, False: 0]
  ------------------
 1165|      0|                                tif, &ndir, dir, tag, count,
 1166|      0|                                (float *)tif->tif_dir.td_customValues[m].value))
 1167|      0|                            goto bad;
 1168|       |                        /*-- ToDo: After Testing, this should be removed and
 1169|       |                         * tv_size==4 should be set as default. */
 1170|      0|                        if (tv_size != 4)
  ------------------
  |  Branch (1170:29): [True: 0, False: 0]
  ------------------
 1171|      0|                        {
 1172|      0|                            TIFFErrorExtR(
 1173|      0|                                tif, "TIFFLib: _TIFFWriteDirectorySec()",
 1174|      0|                                "Rational2Double: .set_get_field_type is "
 1175|      0|                                "not 4 but %d",
 1176|      0|                                tv_size);
 1177|      0|                        }
 1178|      0|                    }
 1179|      0|                }
 1180|      0|                break;
 1181|      0|                case TIFF_FLOAT:
  ------------------
  |  Branch (1181:17): [True: 0, False: 0]
  ------------------
 1182|      0|                    if (!TIFFWriteDirectoryTagFloatArray(
  ------------------
  |  Branch (1182:25): [True: 0, False: 0]
  ------------------
 1183|      0|                            tif, &ndir, dir, tag, count,
 1184|      0|                            (float *)tif->tif_dir.td_customValues[m].value))
 1185|      0|                        goto bad;
 1186|      0|                    break;
 1187|      0|                case TIFF_DOUBLE:
  ------------------
  |  Branch (1187:17): [True: 0, False: 0]
  ------------------
 1188|      0|                    if (!TIFFWriteDirectoryTagDoubleArray(
  ------------------
  |  Branch (1188:25): [True: 0, False: 0]
  ------------------
 1189|      0|                            tif, &ndir, dir, tag, count,
 1190|      0|                            (double *)tif->tif_dir.td_customValues[m].value))
 1191|      0|                        goto bad;
 1192|      0|                    break;
 1193|      0|                case TIFF_IFD:
  ------------------
  |  Branch (1193:17): [True: 0, False: 0]
  ------------------
 1194|      0|                    if (!TIFFWriteDirectoryTagIfdArray(
  ------------------
  |  Branch (1194:25): [True: 0, False: 0]
  ------------------
 1195|      0|                            tif, &ndir, dir, tag, count,
 1196|      0|                            (uint32_t *)tif->tif_dir.td_customValues[m].value))
 1197|      0|                        goto bad;
 1198|      0|                    break;
 1199|      0|                case TIFF_IFD8:
  ------------------
  |  Branch (1199:17): [True: 0, False: 0]
  ------------------
 1200|      0|                    if (!TIFFWriteDirectoryTagIfdIfd8Array(
  ------------------
  |  Branch (1200:25): [True: 0, False: 0]
  ------------------
 1201|      0|                            tif, &ndir, dir, tag, count,
 1202|      0|                            (uint64_t *)tif->tif_dir.td_customValues[m].value))
 1203|      0|                        goto bad;
 1204|      0|                    break;
 1205|      0|                case TIFF_NOTYPE:
  ------------------
  |  Branch (1205:17): [True: 0, False: 0]
  ------------------
 1206|      0|                default:
  ------------------
  |  Branch (1206:17): [True: 0, False: 0]
  ------------------
 1207|      0|                    TIFFErrorExtR(tif, module,
 1208|      0|                                  "Cannot write custom field with tag %" PRIu32
 1209|      0|                                  ": unhandled field type %u",
 1210|      0|                                  (uint32_t)tif->tif_dir.td_customValues[m]
 1211|      0|                                      .info->field_tag,
 1212|      0|                                  (unsigned)tif->tif_dir.td_customValues[m]
 1213|      0|                                      .info->field_type);
 1214|      0|                    goto bad;
 1215|      0|            }
 1216|      0|        }
 1217|       |        /* "break" if IFD has been written above in second pass.*/
 1218|    340|        if (dir != NULL)
  ------------------
  |  Branch (1218:13): [True: 170, False: 170]
  ------------------
 1219|    170|            break;
 1220|       |
 1221|       |        /* Evaluate IFD data size: Finally, add the size of the IFD tag entries
 1222|       |         * themselves. */
 1223|    170|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    170|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1223:13): [True: 170, False: 0]
  ------------------
 1224|    170|            tif->tif_dir.td_dirdatasize_write += 2 + ndir * 12 + 4;
 1225|      0|        else
 1226|      0|            tif->tif_dir.td_dirdatasize_write += 8 + ndir * 20 + 8;
 1227|       |
 1228|       |        /* Setup a new directory within first pass. */
 1229|    170|        dir = (TIFFDirEntry *)_TIFFCheckMalloc(tif, ndir, sizeof(TIFFDirEntry),
 1230|    170|                                               module);
 1231|    170|        if (dir == NULL)
  ------------------
  |  Branch (1231:13): [True: 0, False: 170]
  ------------------
 1232|      0|        {
 1233|      0|            TIFFErrorExtR(tif, module, "Out of memory");
 1234|      0|            goto bad;
 1235|      0|        }
 1236|    170|        if (isimage)
  ------------------
  |  Branch (1236:13): [True: 170, False: 0]
  ------------------
 1237|    170|        {
 1238|       |            /* Check, weather the IFD to be written is new or an already written
 1239|       |             * IFD can be overwritten or needs to be re-written to a different
 1240|       |             * location in the file because the IFD is extended with additional
 1241|       |             * tags or the IFD data size is increased.
 1242|       |             * - tif_diroff == 0, if a new directory has to be linked.
 1243|       |             * - tif_diroff != 0, IFD has been re-read from file and will be
 1244|       |             *   overwritten or re-written.
 1245|       |             */
 1246|    170|            if (tif->tif_diroff == 0)
  ------------------
  |  Branch (1246:17): [True: 170, False: 0]
  ------------------
 1247|    170|            {
 1248|    170|                if (!TIFFLinkDirectory(tif))
  ------------------
  |  Branch (1248:21): [True: 0, False: 170]
  ------------------
 1249|      0|                    goto bad;
 1250|    170|            }
 1251|      0|            else if (tif->tif_dir.td_dirdatasize_write >
  ------------------
  |  Branch (1251:22): [True: 0, False: 0]
  ------------------
 1252|      0|                     tif->tif_dir.td_dirdatasize_read)
 1253|      0|            {
 1254|      0|                if (dir != NULL)
  ------------------
  |  Branch (1254:21): [True: 0, False: 0]
  ------------------
 1255|      0|                {
 1256|      0|                    _TIFFfreeExt(tif, dir);
 1257|      0|                    dir = NULL;
 1258|      0|                }
 1259|      0|                if (!TIFFRewriteDirectorySec(tif, isimage, imagedone, pdiroff))
  ------------------
  |  Branch (1259:21): [True: 0, False: 0]
  ------------------
 1260|      0|                    goto bad;
 1261|      0|                return (1);
 1262|      0|            }
 1263|    170|        }
 1264|      0|        else
 1265|      0|        {
 1266|       |            /* For !isimage, which means custom-IFD like EXIFIFD or
 1267|       |             * checkpointing an IFD, determine whether to overwrite or append at
 1268|       |             * the end of the file.
 1269|       |             */
 1270|      0|            if (!((tif->tif_dir.td_dirdatasize_read > 0) &&
  ------------------
  |  Branch (1270:19): [True: 0, False: 0]
  ------------------
 1271|      0|                  (tif->tif_dir.td_dirdatasize_write <=
  ------------------
  |  Branch (1271:19): [True: 0, False: 0]
  ------------------
 1272|      0|                   tif->tif_dir.td_dirdatasize_read)))
 1273|      0|            {
 1274|       |                /* Append at end of file and increment to an even offset. */
 1275|      0|                const toff_t end_offset = TIFFSeekFile(tif, 0, SEEK_END);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 1276|      0|                if (end_offset == (toff_t)-1)
  ------------------
  |  Branch (1276:21): [True: 0, False: 0]
  ------------------
 1277|      0|                {
 1278|      0|                    TIFFErrorExtR(tif, module,
 1279|      0|                                  "Error seeking to end of file before "
 1280|      0|                                  "writing custom directory");
 1281|      0|                    goto bad;
 1282|      0|                }
 1283|      0|                tif->tif_diroff = (end_offset + 1) & (~((toff_t)1));
 1284|      0|            }
 1285|      0|        }
 1286|       |        /* Return IFD offset */
 1287|    170|        if (pdiroff != NULL)
  ------------------
  |  Branch (1287:13): [True: 0, False: 170]
  ------------------
 1288|      0|            *pdiroff = tif->tif_diroff;
 1289|    170|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    170|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1289:13): [True: 170, False: 0]
  ------------------
 1290|    170|            dirsize = 2 + ndir * 12 + 4;
 1291|      0|        else
 1292|      0|            dirsize = 8 + ndir * 20 + 8;
 1293|       |        /* Append IFD data stright after the IFD tag entries.
 1294|       |         * Data that does not fit into an IFD tag entry is written to the file
 1295|       |         * in the second pass of the while loop. That offset is stored in "dir".
 1296|       |         */
 1297|    170|        tif->tif_dataoff = tif->tif_diroff + dirsize;
 1298|    170|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    170|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1298:13): [True: 170, False: 0]
  ------------------
 1299|    170|            tif->tif_dataoff = (uint32_t)tif->tif_dataoff;
 1300|    170|        if ((tif->tif_dataoff < tif->tif_diroff) ||
  ------------------
  |  Branch (1300:13): [True: 0, False: 170]
  ------------------
 1301|    170|            (tif->tif_dataoff < (uint64_t)dirsize))
  ------------------
  |  Branch (1301:13): [True: 0, False: 170]
  ------------------
 1302|      0|        {
 1303|      0|            TIFFErrorExtR(tif, module, "Maximum TIFF file size exceeded");
 1304|      0|            goto bad;
 1305|      0|        }
 1306|    170|        if (tif->tif_dataoff & 1)
  ------------------
  |  Branch (1306:13): [True: 0, False: 170]
  ------------------
 1307|      0|            tif->tif_dataoff++;
 1308|    170|    } /* while() */
 1309|    170|    if (isimage)
  ------------------
  |  Branch (1309:9): [True: 170, False: 0]
  ------------------
 1310|    170|    {
 1311|       |        /* For SubIFDs remember offset of SubIFD tag within main IFD.
 1312|       |         * However, might be already done in TIFFWriteDirectoryTagSubifd() if
 1313|       |         * there are more than one SubIFD. */
 1314|    170|        if (TIFFFieldSet(tif, FIELD_SUBIFD) && (tif->tif_subifdoff == 0))
  ------------------
  |  |  267|    340|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    170|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    170|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  |  |  |  Branch (267:34): [True: 0, False: 170]
  |  |  ------------------
  ------------------
  |  Branch (1314:48): [True: 0, False: 0]
  ------------------
 1315|      0|        {
 1316|      0|            uint32_t na;
 1317|      0|            TIFFDirEntry *nb;
 1318|      0|            for (na = 0, nb = dir;; na++, nb++)
 1319|      0|            {
 1320|      0|                if (na == ndir)
  ------------------
  |  Branch (1320:21): [True: 0, False: 0]
  ------------------
 1321|      0|                {
 1322|      0|                    TIFFErrorExtR(tif, module, "Cannot find SubIFD tag");
 1323|      0|                    goto bad;
 1324|      0|                }
 1325|      0|                if (nb->tdir_tag == TIFFTAG_SUBIFD)
  ------------------
  |  |  321|      0|#define TIFFTAG_SUBIFD 330                 /* subimage descriptors */
  ------------------
  |  Branch (1325:21): [True: 0, False: 0]
  ------------------
 1326|      0|                    break;
 1327|      0|            }
 1328|      0|            if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1328:17): [True: 0, False: 0]
  ------------------
 1329|      0|                tif->tif_subifdoff = tif->tif_diroff + 2 + na * 12 + 8;
 1330|      0|            else
 1331|      0|                tif->tif_subifdoff = tif->tif_diroff + 8 + na * 20 + 12;
 1332|      0|        }
 1333|    170|    }
 1334|       |    /* Copy/swab IFD entries from "dir" into "dirmem",
 1335|       |     * which is then written to file. */
 1336|    170|    dirmem = _TIFFmallocExt(tif, dirsize);
 1337|    170|    if (dirmem == NULL)
  ------------------
  |  Branch (1337:9): [True: 0, False: 170]
  ------------------
 1338|      0|    {
 1339|      0|        TIFFErrorExtR(tif, module, "Out of memory");
 1340|      0|        goto bad;
 1341|      0|    }
 1342|    170|    if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    170|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (1342:9): [True: 170, False: 0]
  ------------------
 1343|    170|    {
 1344|    170|        uint8_t *n;
 1345|    170|        uint32_t nTmp;
 1346|    170|        TIFFDirEntry *o;
 1347|    170|        n = (uint8_t *)dirmem;
 1348|    170|        *(uint16_t *)n = (uint16_t)ndir;
 1349|    170|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    170|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1349:13): [True: 0, False: 170]
  ------------------
 1350|      0|            TIFFSwabShort((uint16_t *)n);
 1351|    170|        n += 2;
 1352|    170|        o = dir;
 1353|  1.84k|        for (m = 0; m < ndir; m++)
  ------------------
  |  Branch (1353:21): [True: 1.67k, False: 170]
  ------------------
 1354|  1.67k|        {
 1355|  1.67k|            *(uint16_t *)n = o->tdir_tag;
 1356|  1.67k|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|  1.67k|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1356:17): [True: 0, False: 1.67k]
  ------------------
 1357|      0|                TIFFSwabShort((uint16_t *)n);
 1358|  1.67k|            n += 2;
 1359|  1.67k|            *(uint16_t *)n = o->tdir_type;
 1360|  1.67k|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|  1.67k|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1360:17): [True: 0, False: 1.67k]
  ------------------
 1361|      0|                TIFFSwabShort((uint16_t *)n);
 1362|  1.67k|            n += 2;
 1363|  1.67k|            nTmp = (uint32_t)o->tdir_count;
 1364|  1.67k|            _TIFFmemcpy(n, &nTmp, 4);
 1365|  1.67k|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|  1.67k|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1365:17): [True: 0, False: 1.67k]
  ------------------
 1366|      0|                TIFFSwabLong((uint32_t *)n);
 1367|  1.67k|            n += 4;
 1368|       |            /* This is correct. The data has been */
 1369|       |            /* swabbed previously in TIFFWriteDirectoryTagData */
 1370|  1.67k|            _TIFFmemcpy(n, &o->tdir_offset, 4);
 1371|  1.67k|            n += 4;
 1372|  1.67k|            o++;
 1373|  1.67k|        }
 1374|    170|        nTmp = (uint32_t)tif->tif_nextdiroff;
 1375|    170|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    170|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1375:13): [True: 0, False: 170]
  ------------------
 1376|      0|            TIFFSwabLong(&nTmp);
 1377|    170|        _TIFFmemcpy(n, &nTmp, 4);
 1378|    170|    }
 1379|      0|    else
 1380|      0|    {
 1381|      0|        uint8_t *n;
 1382|      0|        TIFFDirEntry *o;
 1383|      0|        n = (uint8_t *)dirmem;
 1384|      0|        *(uint64_t *)n = ndir;
 1385|      0|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1385:13): [True: 0, False: 0]
  ------------------
 1386|      0|            TIFFSwabLong8((uint64_t *)n);
 1387|      0|        n += 8;
 1388|      0|        o = dir;
 1389|      0|        for (m = 0; m < ndir; m++)
  ------------------
  |  Branch (1389:21): [True: 0, False: 0]
  ------------------
 1390|      0|        {
 1391|      0|            *(uint16_t *)n = o->tdir_tag;
 1392|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1392:17): [True: 0, False: 0]
  ------------------
 1393|      0|                TIFFSwabShort((uint16_t *)n);
 1394|      0|            n += 2;
 1395|      0|            *(uint16_t *)n = o->tdir_type;
 1396|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1396:17): [True: 0, False: 0]
  ------------------
 1397|      0|                TIFFSwabShort((uint16_t *)n);
 1398|      0|            n += 2;
 1399|      0|            _TIFFmemcpy(n, &o->tdir_count, 8);
 1400|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1400:17): [True: 0, False: 0]
  ------------------
 1401|      0|                TIFFSwabLong8((uint64_t *)n);
 1402|      0|            n += 8;
 1403|      0|            _TIFFmemcpy(n, &o->tdir_offset, 8);
 1404|      0|            n += 8;
 1405|      0|            o++;
 1406|      0|        }
 1407|      0|        _TIFFmemcpy(n, &tif->tif_nextdiroff, 8);
 1408|      0|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (1408:13): [True: 0, False: 0]
  ------------------
 1409|      0|            TIFFSwabLong8((uint64_t *)n);
 1410|      0|    }
 1411|    170|    _TIFFfreeExt(tif, dir);
 1412|    170|    dir = NULL;
 1413|    170|    if (!SeekOK(tif, tif->tif_diroff))
  ------------------
  |  |  307|    170|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
  |  Branch (1413:9): [True: 0, False: 170]
  ------------------
 1414|      0|    {
 1415|      0|        TIFFErrorExtR(tif, module,
 1416|      0|                      "IO error writing directory at seek to offset");
 1417|      0|        goto bad;
 1418|      0|    }
 1419|    170|    if (!WriteOK(tif, dirmem, (tmsize_t)dirsize))
  ------------------
  |  |  311|    170|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|    170|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (1419:9): [True: 0, False: 170]
  ------------------
 1420|      0|    {
 1421|      0|        TIFFErrorExtR(tif, module, "IO error writing directory");
 1422|      0|        goto bad;
 1423|      0|    }
 1424|    170|    _TIFFfreeExt(tif, dirmem);
 1425|    170|    dirmem = NULL;
 1426|       |
 1427|       |    /* Increment tif_curdir if IFD wasn't already written to file and no error
 1428|       |     * occurred during IFD writing above. */
 1429|    170|    if (isimage && !tif->tif_dir.td_iswrittentofile)
  ------------------
  |  Branch (1429:9): [True: 170, False: 0]
  |  Branch (1429:20): [True: 170, False: 0]
  ------------------
 1430|    170|    {
 1431|    170|        if (!((tif->tif_flags & TIFF_INSUBIFD) &&
  ------------------
  |  |  135|    170|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (1431:15): [True: 0, False: 170]
  ------------------
 1432|      0|              !(TIFFFieldSet(tif, FIELD_SUBIFD))))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  |  Branch (1432:15): [True: 0, False: 0]
  ------------------
 1433|    170|        {
 1434|       |            /*-- Normal main-IFD case --*/
 1435|    170|            if (tif->tif_curdircount != TIFF_NON_EXISTENT_DIR_NUMBER)
  ------------------
  |  |   68|    170|#define TIFF_NON_EXISTENT_DIR_NUMBER UINT_MAX
  ------------------
  |  Branch (1435:17): [True: 170, False: 0]
  ------------------
 1436|    170|            {
 1437|    170|                tif->tif_curdir = tif->tif_curdircount;
 1438|    170|            }
 1439|      0|            else
 1440|      0|            {
 1441|       |                /*ToDo SU: NEW_IFD_CURDIR_INCREMENTING:  Delete this
 1442|       |                 * unexpected case after some testing time. */
 1443|       |                /* Attention: tif->tif_curdircount is already set within
 1444|       |                 * TIFFNumberOfDirectories() */
 1445|      0|                tif->tif_curdircount = TIFFNumberOfDirectories(tif);
 1446|      0|                tif->tif_curdir = tif->tif_curdircount;
 1447|      0|                TIFFErrorExtR(
 1448|      0|                    tif, module,
 1449|      0|                    "tif_curdircount is TIFF_NON_EXISTENT_DIR_NUMBER, "
 1450|      0|                    "not expected !! Line %d",
 1451|      0|                    __LINE__);
 1452|      0|                goto bad;
 1453|      0|            }
 1454|    170|        }
 1455|      0|        else
 1456|      0|        {
 1457|       |            /*-- SubIFD case -- */
 1458|       |            /* tif_curdir is always set to 0 for all SubIFDs. */
 1459|      0|            tif->tif_curdir = 0;
 1460|      0|        }
 1461|    170|    }
 1462|       |    /* Increment tif_curdircount only if main-IFD of an image was not already
 1463|       |     * present on file. */
 1464|       |    /* Check in combination with (... && !(TIFFFieldSet(tif, FIELD_SUBIFD)))
 1465|       |     * is necessary here because TIFF_INSUBIFD was already set above for the
 1466|       |     * next SubIFD when this main-IFD (with FIELD_SUBIFD) is currently being
 1467|       |     * written. */
 1468|    170|    if (isimage && !tif->tif_dir.td_iswrittentofile &&
  ------------------
  |  Branch (1468:9): [True: 170, False: 0]
  |  Branch (1468:20): [True: 170, False: 0]
  ------------------
 1469|    170|        !((tif->tif_flags & TIFF_INSUBIFD) &&
  ------------------
  |  |  135|    170|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (1469:11): [True: 0, False: 170]
  ------------------
 1470|      0|          !(TIFFFieldSet(tif, FIELD_SUBIFD))))
  ------------------
  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  |  Branch (1470:11): [True: 0, False: 0]
  ------------------
 1471|    170|        tif->tif_curdircount++;
 1472|       |
 1473|    170|    tif->tif_dir.td_iswrittentofile = TRUE;
  ------------------
  |  |   74|    170|#define TRUE 1
  ------------------
 1474|       |
 1475|       |    /* Reset SubIFD writing stage after last SubIFD has been written. */
 1476|    170|    if (imagedone && (tif->tif_flags & TIFF_INSUBIFD) && tif->tif_nsubifd == 0)
  ------------------
  |  |  135|    170|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (1476:9): [True: 170, False: 0]
  |  Branch (1476:22): [True: 0, False: 170]
  |  Branch (1476:58): [True: 0, False: 0]
  ------------------
 1477|      0|        tif->tif_flags &= ~TIFF_INSUBIFD;
  ------------------
  |  |  135|      0|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
 1478|       |
 1479|       |    /* Add or update this directory to the IFD list. */
 1480|    170|    if (!_TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, tif->tif_diroff))
  ------------------
  |  Branch (1480:9): [True: 0, False: 170]
  ------------------
 1481|      0|    {
 1482|      0|        TIFFErrorExtR(tif, module,
 1483|      0|                      "Starting directory %u at offset 0x%" PRIx64 " (%" PRIu64
 1484|      0|                      ") might cause an IFD loop",
 1485|      0|                      tif->tif_curdir, tif->tif_diroff, tif->tif_diroff);
 1486|      0|    }
 1487|       |
 1488|    170|    if (imagedone)
  ------------------
  |  Branch (1488:9): [True: 170, False: 0]
  ------------------
 1489|    170|    {
 1490|    170|        TIFFFreeDirectory(tif);
 1491|    170|        tif->tif_flags &= ~TIFF_DIRTYDIRECT;
  ------------------
  |  |  125|    170|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
 1492|    170|        tif->tif_flags &= ~TIFF_DIRTYSTRIP;
  ------------------
  |  |  145|    170|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
 1493|       |        /* Reset directory-related state for subsequent directories. */
 1494|    170|        TIFFCreateDirectory(tif);
 1495|    170|    }
 1496|      0|    else
 1497|      0|    {
 1498|       |        /* IFD is only checkpointed to file (or a custom IFD like EXIF is
 1499|       |         * written), thus set IFD data size written to file. */
 1500|      0|        tif->tif_dir.td_dirdatasize_read = tif->tif_dir.td_dirdatasize_write;
 1501|      0|    }
 1502|    170|    return (1);
 1503|     37|bad:
 1504|     37|    if (dir != NULL)
  ------------------
  |  Branch (1504:9): [True: 0, False: 37]
  ------------------
 1505|      0|        _TIFFfreeExt(tif, dir);
 1506|     37|    if (dirmem != NULL)
  ------------------
  |  Branch (1506:9): [True: 0, False: 37]
  ------------------
 1507|      0|        _TIFFfreeExt(tif, dirmem);
 1508|     37|    return (0);
 1509|    170|}
tif_dirwrite.c:TIFFWriteDirectoryTagShortLong:
 1946|  1.13k|{
 1947|  1.13k|    if (value <= 0xFFFF)
  ------------------
  |  Branch (1947:9): [True: 1.13k, False: 0]
  ------------------
 1948|  1.13k|        return (TIFFWriteDirectoryTagCheckedShort(tif, ndir, dir, tag,
 1949|  1.13k|                                                  (uint16_t)value));
 1950|      0|    else
 1951|      0|        return (TIFFWriteDirectoryTagCheckedLong(tif, ndir, dir, tag, value));
 1952|  1.13k|}
tif_dirwrite.c:TIFFWriteDirectoryTagCheckedShort:
 2466|  2.58k|{
 2467|  2.58k|    uint16_t m;
 2468|  2.58k|    assert(sizeof(uint16_t) == 2);
  ------------------
  |  Branch (2468:5): [True: 0, Folded]
  |  Branch (2468:5): [True: 2.58k, Folded]
  ------------------
 2469|  2.58k|    if (dir == NULL)
  ------------------
  |  Branch (2469:9): [True: 1.41k, False: 1.16k]
  ------------------
 2470|  1.41k|    {
 2471|       |        /* No additional data to IFD data size just increment ndir. */
 2472|  1.41k|        (*ndir)++;
 2473|  1.41k|        return 1;
 2474|  1.41k|    }
 2475|  1.16k|    m = value;
 2476|  1.16k|    if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|  1.16k|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (2476:9): [True: 0, False: 1.16k]
  ------------------
 2477|      0|        TIFFSwabShort(&m);
 2478|  1.16k|    return (
 2479|  1.16k|        TIFFWriteDirectoryTagData(tif, ndir, dir, tag, TIFF_SHORT, 1, 2, &m));
 2480|  2.58k|}
tif_dirwrite.c:TIFFWriteDirectoryTagData:
 3229|  1.67k|{
 3230|  1.67k|    static const char module[] = "TIFFWriteDirectoryTagData";
 3231|  1.67k|    uint32_t m;
 3232|  1.67k|    m = 0;
 3233|  8.29k|    while (m < (*ndir))
  ------------------
  |  Branch (3233:12): [True: 6.93k, False: 1.36k]
  ------------------
 3234|  6.93k|    {
 3235|  6.93k|        assert(dir[m].tdir_tag != tag);
  ------------------
  |  Branch (3235:9): [True: 0, False: 6.93k]
  |  Branch (3235:9): [True: 6.93k, False: 0]
  ------------------
 3236|  6.93k|        if (dir[m].tdir_tag > tag)
  ------------------
  |  Branch (3236:13): [True: 314, False: 6.61k]
  ------------------
 3237|    314|            break;
 3238|  6.61k|        m++;
 3239|  6.61k|    }
 3240|  1.67k|    if (m < (*ndir))
  ------------------
  |  Branch (3240:9): [True: 314, False: 1.36k]
  ------------------
 3241|    314|    {
 3242|    314|        uint32_t n;
 3243|  1.11k|        for (n = *ndir; n > m; n--)
  ------------------
  |  Branch (3243:25): [True: 798, False: 314]
  ------------------
 3244|    798|            dir[n] = dir[n - 1];
 3245|    314|    }
 3246|  1.67k|    dir[m].tdir_tag = tag;
 3247|  1.67k|    dir[m].tdir_type = datatype;
 3248|  1.67k|    dir[m].tdir_count = count;
 3249|  1.67k|    dir[m].tdir_offset.toff_long8 = 0;
 3250|  1.67k|    if (datalength <= ((tif->tif_flags & TIFF_BIGTIFF) ? 0x8U : 0x4U))
  ------------------
  |  |  143|  1.67k|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (3250:9): [True: 1.33k, False: 340]
  |  Branch (3250:24): [True: 0, False: 1.67k]
  ------------------
 3251|  1.33k|    {
 3252|  1.33k|        if (data && datalength)
  ------------------
  |  Branch (3252:13): [True: 1.33k, False: 0]
  |  Branch (3252:21): [True: 1.33k, False: 0]
  ------------------
 3253|  1.33k|        {
 3254|  1.33k|            _TIFFmemcpy(&dir[m].tdir_offset, data, datalength);
 3255|  1.33k|        }
 3256|  1.33k|    }
 3257|    340|    else
 3258|    340|    {
 3259|    340|        uint64_t na, nb;
 3260|    340|        na = tif->tif_dataoff;
 3261|    340|        nb = na + datalength;
 3262|    340|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    340|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (3262:13): [True: 340, False: 0]
  ------------------
 3263|    340|            nb = (uint32_t)nb;
 3264|    340|        if ((nb < na) || (nb < datalength))
  ------------------
  |  Branch (3264:13): [True: 0, False: 340]
  |  Branch (3264:26): [True: 0, False: 340]
  ------------------
 3265|      0|        {
 3266|      0|            TIFFErrorExtR(tif, module, "Maximum TIFF file size exceeded");
 3267|      0|            return (0);
 3268|      0|        }
 3269|    340|        if (!SeekOK(tif, na))
  ------------------
  |  |  307|    340|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
  |  Branch (3269:13): [True: 0, False: 340]
  ------------------
 3270|      0|        {
 3271|      0|            TIFFErrorExtR(tif, module, "IO error writing tag data");
 3272|      0|            return (0);
 3273|      0|        }
 3274|    340|        if (datalength >= 0x80000000UL)
  ------------------
  |  Branch (3274:13): [True: 0, False: 340]
  ------------------
 3275|      0|        {
 3276|      0|            TIFFErrorExtR(tif, module,
 3277|      0|                          "libtiff does not allow writing more than 2147483647 "
 3278|      0|                          "bytes in a tag");
 3279|      0|            return (0);
 3280|      0|        }
 3281|    340|        if (!WriteOK(tif, data, (tmsize_t)datalength))
  ------------------
  |  |  311|    340|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|    340|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3281:13): [True: 0, False: 340]
  ------------------
 3282|      0|        {
 3283|      0|            TIFFErrorExtR(tif, module, "IO error writing tag data");
 3284|      0|            return (0);
 3285|      0|        }
 3286|    340|        tif->tif_dataoff = nb;
 3287|    340|        if (tif->tif_dataoff & 1)
  ------------------
  |  Branch (3287:13): [True: 0, False: 340]
  ------------------
 3288|      0|            tif->tif_dataoff++;
 3289|    340|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    340|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (3289:13): [True: 340, False: 0]
  ------------------
 3290|    340|        {
 3291|    340|            uint32_t o;
 3292|    340|            o = (uint32_t)na;
 3293|    340|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    340|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3293:17): [True: 0, False: 340]
  ------------------
 3294|      0|                TIFFSwabLong(&o);
 3295|    340|            _TIFFmemcpy(&dir[m].tdir_offset, &o, 4);
 3296|    340|        }
 3297|      0|        else
 3298|      0|        {
 3299|      0|            dir[m].tdir_offset.toff_long8 = na;
 3300|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3300:17): [True: 0, False: 0]
  ------------------
 3301|      0|                TIFFSwabLong8(&dir[m].tdir_offset.toff_long8);
 3302|      0|        }
 3303|    340|    }
 3304|  1.67k|    (*ndir)++;
 3305|  1.67k|    return (1);
 3306|  1.67k|}
tif_dirwrite.c:TIFFWriteDirectoryTagShortPerSample:
 1701|    377|{
 1702|    377|    static const char module[] = "TIFFWriteDirectoryTagShortPerSample";
 1703|    377|    uint16_t *m;
 1704|    377|    uint16_t *na;
 1705|    377|    uint16_t nb;
 1706|    377|    int o;
 1707|    377|    if (dir == NULL)
  ------------------
  |  Branch (1707:9): [True: 207, False: 170]
  ------------------
 1708|    207|    {
 1709|       |        /* only evaluate IFD data size and inc. ndir */
 1710|    207|        return (TIFFWriteDirectoryTagCheckedShortArray(
 1711|    207|            tif, ndir, dir, tag, tif->tif_dir.td_samplesperpixel, NULL));
 1712|    207|    }
 1713|    170|    m = (uint16_t *)_TIFFCheckMalloc(tif, tif->tif_dir.td_samplesperpixel,
 1714|    170|                                     sizeof(uint16_t), module);
 1715|    170|    if (m == NULL)
  ------------------
  |  Branch (1715:9): [True: 0, False: 170]
  ------------------
 1716|      0|    {
 1717|      0|        TIFFErrorExtR(tif, module, "Out of memory");
 1718|      0|        return (0);
 1719|      0|    }
 1720|    340|    for (na = m, nb = 0; nb < tif->tif_dir.td_samplesperpixel; na++, nb++)
  ------------------
  |  Branch (1720:26): [True: 170, False: 170]
  ------------------
 1721|    170|        *na = value;
 1722|    170|    o = TIFFWriteDirectoryTagCheckedShortArray(
 1723|    170|        tif, ndir, dir, tag, tif->tif_dir.td_samplesperpixel, m);
 1724|    170|    _TIFFfreeExt(tif, m);
 1725|    170|    return (o);
 1726|    170|}
tif_dirwrite.c:TIFFWriteDirectoryTagCheckedShortArray:
 2486|    717|{
 2487|    717|    static const char module[] = "TIFFWriteDirectoryTagCheckedShortArray";
 2488|    717|    if (count > UINT32_MAX / 2)
  ------------------
  |  Branch (2488:9): [True: 0, False: 717]
  ------------------
 2489|      0|    {
 2490|      0|        TIFFErrorExtR(tif, module,
 2491|      0|                      "Tag %" PRIu16 ": count %" PRIu32
 2492|      0|                      " exceeds maximum of %" PRIu32 " entries",
 2493|      0|                      tag, count, UINT32_MAX / 2);
 2494|      0|        return (0);
 2495|      0|    }
 2496|    717|    if (dir == NULL) /* Just evaluate IFD data size and increment ndir. */
  ------------------
  |  Branch (2496:9): [True: 377, False: 340]
  ------------------
 2497|    377|    {
 2498|    377|        EvaluateIFDdatasizeWrite(tif, count, 2, ndir);
 2499|    377|        return 1;
 2500|    377|    }
 2501|    340|    if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    340|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (2501:9): [True: 0, False: 340]
  ------------------
 2502|      0|        TIFFSwabArrayOfShort(value, count);
 2503|    340|    return (TIFFWriteDirectoryTagData(tif, ndir, dir, tag, TIFF_SHORT, count,
 2504|    340|                                      count * 2, value));
 2505|    717|}
tif_dirwrite.c:EvaluateIFDdatasizeWrite:
 2181|    547|{
 2182|    547|    uint64_t datalength = (uint64_t)count * typesize;
 2183|    547|    if (datalength > ((tif->tif_flags & TIFF_BIGTIFF) ? 0x8U : 0x4U))
  ------------------
  |  |  143|    547|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (2183:9): [True: 340, False: 207]
  |  Branch (2183:23): [True: 0, False: 547]
  ------------------
 2184|    340|    {
 2185|       |        /* LibTIFF increments write address to an even offset, thus datalength
 2186|       |         * written is also incremented. */
 2187|    340|        if (datalength & 1)
  ------------------
  |  Branch (2187:13): [True: 0, False: 340]
  ------------------
 2188|      0|            datalength++;
 2189|    340|        tif->tif_dir.td_dirdatasize_write += datalength;
 2190|    340|    }
 2191|    547|    (*ndir)++;
 2192|    547|}
tif_dirwrite.c:TIFFWriteDirectoryTagShort:
 1686|  1.45k|{
 1687|  1.45k|    return (TIFFWriteDirectoryTagCheckedShort(tif, ndir, dir, tag, value));
 1688|  1.45k|}
tif_dirwrite.c:TIFFWriteDirectoryTagLongLong8Array:
 1999|    717|{
 2000|    717|    static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";
 2001|    717|    int o;
 2002|    717|    int write_aslong4;
 2003|       |
 2004|    717|    if (tif->tif_dir.td_deferstrilearraywriting)
  ------------------
  |  Branch (2004:9): [True: 0, False: 717]
  ------------------
 2005|      0|    {
 2006|      0|        if (dir == NULL)
  ------------------
  |  Branch (2006:13): [True: 0, False: 0]
  ------------------
 2007|      0|        {
 2008|       |            /* This is just a counting pass to count IFD entries.
 2009|       |             * For deferstrilearraywriting no extra bytes will be written
 2010|       |             * into IFD space. */
 2011|      0|            (*ndir)++;
 2012|      0|            return 1;
 2013|      0|        }
 2014|      0|        return TIFFWriteDirectoryTagData(tif, ndir, dir, tag, TIFF_NOTYPE, 0, 0,
 2015|      0|                                         NULL);
 2016|      0|    }
 2017|       |
 2018|    717|    if (tif->tif_flags & TIFF_BIGTIFF)
  ------------------
  |  |  143|    717|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (2018:9): [True: 0, False: 717]
  ------------------
 2019|      0|    {
 2020|      0|        int write_aslong8 = 1;
 2021|       |        /* In the case of ByteCounts array, we may be able to write them on LONG
 2022|       |         * if the strip/tilesize is not too big. Also do that for count > 1 in
 2023|       |         * the case someone would want to create a single-strip file with a
 2024|       |         * growing height, in which case using LONG8 will be safer. */
 2025|      0|        if (count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS)
  ------------------
  |  |  259|      0|#define TIFFTAG_STRIPBYTECOUNTS 279        /* bytes counts for strips */
  ------------------
  |  Branch (2025:13): [True: 0, False: 0]
  |  Branch (2025:26): [True: 0, False: 0]
  ------------------
 2026|      0|        {
 2027|      0|            write_aslong8 = WriteAsLong8(tif, TIFFStripSize64(tif));
 2028|      0|        }
 2029|      0|        else if (count > 1 && tag == TIFFTAG_TILEBYTECOUNTS)
  ------------------
  |  |  314|      0|#define TIFFTAG_TILEBYTECOUNTS 325         /* !byte counts for tiles */
  ------------------
  |  Branch (2029:18): [True: 0, False: 0]
  |  Branch (2029:31): [True: 0, False: 0]
  ------------------
 2030|      0|        {
 2031|      0|            write_aslong8 = WriteAsLong8(tif, TIFFTileSize64(tif));
 2032|      0|        }
 2033|      0|        if (write_aslong8)
  ------------------
  |  Branch (2033:13): [True: 0, False: 0]
  ------------------
 2034|      0|        {
 2035|      0|            return TIFFWriteDirectoryTagCheckedLong8Array(tif, ndir, dir, tag,
 2036|      0|                                                          count, value);
 2037|      0|        }
 2038|      0|    }
 2039|       |
 2040|    717|    write_aslong4 = 1;
 2041|    717|    if (count > 1 && tag == TIFFTAG_STRIPBYTECOUNTS)
  ------------------
  |  |  259|    717|#define TIFFTAG_STRIPBYTECOUNTS 279        /* bytes counts for strips */
  ------------------
  |  Branch (2041:9): [True: 717, False: 0]
  |  Branch (2041:22): [True: 377, False: 340]
  ------------------
 2042|    377|    {
 2043|    377|        write_aslong4 = WriteAsLong4(tif, TIFFStripSize64(tif));
 2044|    377|    }
 2045|    340|    else if (count > 1 && tag == TIFFTAG_TILEBYTECOUNTS)
  ------------------
  |  |  314|    340|#define TIFFTAG_TILEBYTECOUNTS 325         /* !byte counts for tiles */
  ------------------
  |  Branch (2045:14): [True: 340, False: 0]
  |  Branch (2045:27): [True: 0, False: 340]
  ------------------
 2046|      0|    {
 2047|      0|        write_aslong4 = WriteAsLong4(tif, TIFFTileSize64(tif));
 2048|      0|    }
 2049|    717|    if (write_aslong4)
  ------------------
  |  Branch (2049:9): [True: 340, False: 377]
  ------------------
 2050|    340|    {
 2051|       |        /*
 2052|       |        ** For classic tiff we want to verify everything is in range for LONG
 2053|       |        ** and convert to long format.
 2054|       |        */
 2055|       |
 2056|    340|        uint32_t *p =
 2057|    340|            (uint32_t *)_TIFFCheckMalloc(tif, count, sizeof(uint32_t), module);
 2058|    340|        uint32_t *q;
 2059|    340|        uint64_t *ma;
 2060|    340|        uint32_t mb;
 2061|       |
 2062|    340|        if (p == NULL)
  ------------------
  |  Branch (2062:13): [True: 0, False: 340]
  ------------------
 2063|      0|        {
 2064|      0|            TIFFErrorExtR(tif, module, "Out of memory");
 2065|      0|            return (0);
 2066|      0|        }
 2067|       |
 2068|  13.9k|        for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
  ------------------
  |  Branch (2068:41): [True: 13.6k, False: 340]
  ------------------
 2069|  13.6k|        {
 2070|  13.6k|            if (*ma > 0xFFFFFFFF)
  ------------------
  |  Branch (2070:17): [True: 0, False: 13.6k]
  ------------------
 2071|      0|            {
 2072|      0|                TIFFErrorExtR(tif, module,
 2073|      0|                              "Attempt to write value larger than 0xFFFFFFFF "
 2074|      0|                              "in LONG array.");
 2075|      0|                _TIFFfreeExt(tif, p);
 2076|      0|                return (0);
 2077|      0|            }
 2078|  13.6k|            *q = (uint32_t)(*ma);
 2079|  13.6k|        }
 2080|       |
 2081|    340|        o = TIFFWriteDirectoryTagCheckedLongArray(tif, ndir, dir, tag, count,
 2082|    340|                                                  p);
 2083|    340|        _TIFFfreeExt(tif, p);
 2084|    340|    }
 2085|    377|    else
 2086|    377|    {
 2087|    377|        uint16_t *p =
 2088|    377|            (uint16_t *)_TIFFCheckMalloc(tif, count, sizeof(uint16_t), module);
 2089|    377|        uint16_t *q;
 2090|    377|        uint64_t *ma;
 2091|    377|        uint32_t mb;
 2092|       |
 2093|    377|        if (p == NULL)
  ------------------
  |  Branch (2093:13): [True: 0, False: 377]
  ------------------
 2094|      0|        {
 2095|      0|            TIFFErrorExtR(tif, module, "Out of memory");
 2096|      0|            return (0);
 2097|      0|        }
 2098|       |
 2099|  13.9k|        for (q = p, ma = value, mb = 0; mb < count; ma++, mb++, q++)
  ------------------
  |  Branch (2099:41): [True: 13.6k, False: 340]
  ------------------
 2100|  13.6k|        {
 2101|  13.6k|            if (*ma > 0xFFFF)
  ------------------
  |  Branch (2101:17): [True: 37, False: 13.6k]
  ------------------
 2102|     37|            {
 2103|       |                /* Should not happen normally given the check we did before */
 2104|     37|                TIFFErrorExtR(tif, module,
 2105|     37|                              "Attempt to write value larger than 0xFFFF in "
 2106|     37|                              "SHORT array.");
 2107|     37|                _TIFFfreeExt(tif, p);
 2108|     37|                return (0);
 2109|     37|            }
 2110|  13.6k|            *q = (uint16_t)(*ma);
 2111|  13.6k|        }
 2112|       |
 2113|    340|        o = TIFFWriteDirectoryTagCheckedShortArray(tif, ndir, dir, tag, count,
 2114|    340|                                                   p);
 2115|    340|        _TIFFfreeExt(tif, p);
 2116|    340|    }
 2117|       |
 2118|    680|    return (o);
 2119|    717|}
tif_dirwrite.c:TIFFWriteDirectoryTagCheckedLongArray:
 2555|    340|{
 2556|    340|    if (count > UINT32_MAX / 4)
  ------------------
  |  Branch (2556:9): [True: 0, False: 340]
  ------------------
 2557|      0|        return (0);
 2558|    340|    if (dir == NULL) /* Just evaluate IFD data size and increment ndir. */
  ------------------
  |  Branch (2558:9): [True: 170, False: 170]
  ------------------
 2559|    170|    {
 2560|    170|        EvaluateIFDdatasizeWrite(tif, count, 4, ndir);
 2561|    170|        return 1;
 2562|    170|    }
 2563|    170|    if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    170|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (2563:9): [True: 0, False: 170]
  ------------------
 2564|      0|        TIFFSwabArrayOfLong(value, count);
 2565|    170|    return (TIFFWriteDirectoryTagData(tif, ndir, dir, tag, TIFF_LONG, count,
 2566|    170|                                      count * 4, value));
 2567|    340|}
tif_dirwrite.c:TIFFLinkDirectory:
 3312|    170|{
 3313|    170|    static const char module[] = "TIFFLinkDirectory";
 3314|       |
 3315|    170|    const toff_t end_offset = TIFFSeekFile(tif, 0, SEEK_END);
  ------------------
  |  |  291|    170|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3316|    170|    if (end_offset == (toff_t)-1)
  ------------------
  |  Branch (3316:9): [True: 0, False: 170]
  ------------------
 3317|      0|    {
 3318|      0|        TIFFErrorExtR(tif, module,
 3319|      0|                      "Error seeking to end of file before linking directory");
 3320|      0|        return 0;
 3321|      0|    }
 3322|    170|    tif->tif_diroff = (end_offset + 1) & (~((toff_t)1));
 3323|       |
 3324|       |    /*
 3325|       |     * Handle SubIFDs
 3326|       |     */
 3327|    170|    if (tif->tif_flags & TIFF_INSUBIFD)
  ------------------
  |  |  135|    170|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (3327:9): [True: 0, False: 170]
  ------------------
 3328|      0|    {
 3329|      0|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (3329:13): [True: 0, False: 0]
  ------------------
 3330|      0|        {
 3331|      0|            uint32_t m;
 3332|      0|            m = (uint32_t)tif->tif_diroff;
 3333|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3333:17): [True: 0, False: 0]
  ------------------
 3334|      0|                TIFFSwabLong(&m);
 3335|      0|            (void)TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3336|      0|            if (!WriteOK(tif, &m, 4))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3336:17): [True: 0, False: 0]
  ------------------
 3337|      0|            {
 3338|      0|                TIFFErrorExtR(tif, module,
 3339|      0|                              "Error writing SubIFD directory link");
 3340|      0|                return (0);
 3341|      0|            }
 3342|       |
 3343|       |            /*
 3344|       |             * Advance to the next SubIFD or, if this is
 3345|       |             * the last one configured, reverting back to the
 3346|       |             * normal directory linkage is done in TIFFWriteDirectorySec()
 3347|       |             * by tif->tif_flags &= ~TIFF_INSUBIFD;.
 3348|       |             */
 3349|      0|            if (--tif->tif_nsubifd)
  ------------------
  |  Branch (3349:17): [True: 0, False: 0]
  ------------------
 3350|      0|                tif->tif_subifdoff += 4;
 3351|      0|            return (1);
 3352|      0|        }
 3353|      0|        else
 3354|      0|        {
 3355|      0|            uint64_t m;
 3356|      0|            m = tif->tif_diroff;
 3357|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3357:17): [True: 0, False: 0]
  ------------------
 3358|      0|                TIFFSwabLong8(&m);
 3359|      0|            (void)TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3360|      0|            if (!WriteOK(tif, &m, 8))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3360:17): [True: 0, False: 0]
  ------------------
 3361|      0|            {
 3362|      0|                TIFFErrorExtR(tif, module,
 3363|      0|                              "Error writing SubIFD directory link");
 3364|      0|                return (0);
 3365|      0|            }
 3366|       |
 3367|       |            /*
 3368|       |             * Advance to the next SubIFD or, if this is
 3369|       |             * the last one configured, reverting back to the
 3370|       |             * normal directory linkage is done in TIFFWriteDirectorySec()
 3371|       |             * by tif->tif_flags &= ~TIFF_INSUBIFD;.
 3372|       |             */
 3373|      0|            if (--tif->tif_nsubifd)
  ------------------
  |  Branch (3373:17): [True: 0, False: 0]
  ------------------
 3374|      0|                tif->tif_subifdoff += 8;
 3375|      0|            return (1);
 3376|      0|        }
 3377|      0|    }
 3378|       |
 3379|       |    /*
 3380|       |     * Handle main-IFDs
 3381|       |     */
 3382|    170|    tdir_t ndir = 1; /* count current number of main-IFDs */
 3383|    170|    if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    170|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (3383:9): [True: 170, False: 0]
  ------------------
 3384|    170|    {
 3385|    170|        uint32_t m;
 3386|    170|        uint32_t nextdir;
 3387|    170|        m = (uint32_t)(tif->tif_diroff);
 3388|    170|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    170|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3388:13): [True: 0, False: 170]
  ------------------
 3389|      0|            TIFFSwabLong(&m);
 3390|    170|        if (tif->tif_header.classic.tiff_diroff == 0)
  ------------------
  |  Branch (3390:13): [True: 170, False: 0]
  ------------------
 3391|    170|        {
 3392|       |            /*
 3393|       |             * First directory, overwrite offset in header.
 3394|       |             */
 3395|    170|            tif->tif_header.classic.tiff_diroff = (uint32_t)tif->tif_diroff;
 3396|    170|            tif->tif_lastdiroff = tif->tif_diroff;
 3397|    170|            (void)TIFFSeekFile(tif, 4, SEEK_SET);
  ------------------
  |  |  291|    170|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3398|    170|            if (!WriteOK(tif, &m, 4))
  ------------------
  |  |  311|    170|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|    170|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3398:17): [True: 0, False: 170]
  ------------------
 3399|      0|            {
 3400|      0|                TIFFErrorExtR(tif, tif->tif_name, "Error writing TIFF header");
 3401|      0|                return (0);
 3402|      0|            }
 3403|    170|            if (!tif->tif_dir.td_iswrittentofile)
  ------------------
  |  Branch (3403:17): [True: 170, False: 0]
  ------------------
 3404|    170|                tif->tif_curdircount = 0;
 3405|    170|            return (1);
 3406|    170|        }
 3407|       |        /*
 3408|       |         * Not the first directory, search to the last and append.
 3409|       |         */
 3410|      0|        tdir_t dirn = 0;
 3411|      0|        if (tif->tif_lastdiroff != 0 &&
  ------------------
  |  Branch (3411:13): [True: 0, False: 0]
  ------------------
 3412|      0|            _TIFFGetDirNumberFromOffset(tif, tif->tif_lastdiroff, &dirn))
  ------------------
  |  Branch (3412:13): [True: 0, False: 0]
  ------------------
 3413|      0|        {
 3414|       |            /* Start searching from the lastely written IFD. Thus get its IFD
 3415|       |             * number. */
 3416|      0|            nextdir = (uint32_t)tif->tif_lastdiroff;
 3417|      0|            ndir = dirn + 1;
 3418|      0|        }
 3419|      0|        else
 3420|      0|        {
 3421|      0|            nextdir = tif->tif_header.classic.tiff_diroff;
 3422|      0|            ndir = 1; /* start searching from the first IFD */
 3423|      0|        }
 3424|       |
 3425|      0|        while (1)
  ------------------
  |  Branch (3425:16): [True: 0, Folded]
  ------------------
 3426|      0|        {
 3427|      0|            uint16_t dircount;
 3428|      0|            uint32_t nextnextdir;
 3429|       |
 3430|       |            /* Update IDF loop list and check for IFD loop.
 3431|       |             * ndir is IFD ID plus one. */
 3432|      0|            if (!_TIFFCheckDirNumberAndOffset(tif, ndir - 1, nextdir))
  ------------------
  |  Branch (3432:17): [True: 0, False: 0]
  ------------------
 3433|      0|            {
 3434|      0|                TIFFErrorExtR(tif, module, "Error IFD loop detected");
 3435|      0|                return 0; /* bad offset (IFD looping or more than
 3436|       |                             TIFF_MAX_DIR_COUNT IFDs) */
 3437|      0|            }
 3438|      0|            if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount, 2))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
                          if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount, 2))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3438:17): [True: 0, False: 0]
  |  Branch (3438:42): [True: 0, False: 0]
  ------------------
 3439|      0|            {
 3440|      0|                TIFFErrorExtR(tif, module, "Error fetching directory count");
 3441|      0|                return (0);
 3442|      0|            }
 3443|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3443:17): [True: 0, False: 0]
  ------------------
 3444|      0|                TIFFSwabShort(&dircount);
 3445|      0|            (void)TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3446|      0|            if (!ReadOK(tif, &nextnextdir, 4))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3446:17): [True: 0, False: 0]
  ------------------
 3447|      0|            {
 3448|      0|                TIFFErrorExtR(tif, module, "Error fetching directory link");
 3449|      0|                return (0);
 3450|      0|            }
 3451|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3451:17): [True: 0, False: 0]
  ------------------
 3452|      0|                TIFFSwabLong(&nextnextdir);
 3453|      0|            if (nextnextdir == 0)
  ------------------
  |  Branch (3453:17): [True: 0, False: 0]
  ------------------
 3454|      0|            {
 3455|      0|                (void)TIFFSeekFile(tif, nextdir + 2 + dircount * 12U, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3456|      0|                if (!WriteOK(tif, &m, 4))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3456:21): [True: 0, False: 0]
  ------------------
 3457|      0|                {
 3458|      0|                    TIFFErrorExtR(tif, module, "Error writing directory link");
 3459|      0|                    return (0);
 3460|      0|                }
 3461|      0|                tif->tif_lastdiroff = tif->tif_diroff;
 3462|      0|                break;
 3463|      0|            }
 3464|      0|            nextdir = nextnextdir;
 3465|      0|            ndir++;
 3466|      0|        }
 3467|      0|    }
 3468|      0|    else
 3469|      0|    {
 3470|       |        /*- BigTIFF -*/
 3471|      0|        uint64_t m;
 3472|      0|        uint64_t nextdir;
 3473|      0|        m = tif->tif_diroff;
 3474|      0|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3474:13): [True: 0, False: 0]
  ------------------
 3475|      0|            TIFFSwabLong8(&m);
 3476|      0|        if (tif->tif_header.big.tiff_diroff == 0)
  ------------------
  |  Branch (3476:13): [True: 0, False: 0]
  ------------------
 3477|      0|        {
 3478|       |            /*
 3479|       |             * First directory, overwrite offset in header.
 3480|       |             */
 3481|      0|            tif->tif_header.big.tiff_diroff = tif->tif_diroff;
 3482|      0|            tif->tif_lastdiroff = tif->tif_diroff;
 3483|      0|            (void)TIFFSeekFile(tif, 8, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3484|      0|            if (!WriteOK(tif, &m, 8))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3484:17): [True: 0, False: 0]
  ------------------
 3485|      0|            {
 3486|      0|                TIFFErrorExtR(tif, tif->tif_name, "Error writing TIFF header");
 3487|      0|                return (0);
 3488|      0|            }
 3489|      0|            if (!tif->tif_dir.td_iswrittentofile)
  ------------------
  |  Branch (3489:17): [True: 0, False: 0]
  ------------------
 3490|      0|                tif->tif_curdircount = 0;
 3491|      0|            return (1);
 3492|      0|        }
 3493|       |        /*
 3494|       |         * Not the first directory, search to the last and append.
 3495|       |         */
 3496|      0|        tdir_t dirn = 0;
 3497|      0|        if (tif->tif_lastdiroff != 0 &&
  ------------------
  |  Branch (3497:13): [True: 0, False: 0]
  ------------------
 3498|      0|            _TIFFGetDirNumberFromOffset(tif, tif->tif_lastdiroff, &dirn))
  ------------------
  |  Branch (3498:13): [True: 0, False: 0]
  ------------------
 3499|      0|        {
 3500|       |            /* Start searching from the lastely written IFD. Thus get its IFD
 3501|       |             * number. */
 3502|      0|            nextdir = tif->tif_lastdiroff;
 3503|      0|            ndir = dirn + 1;
 3504|      0|        }
 3505|      0|        else
 3506|      0|        {
 3507|      0|            nextdir = tif->tif_header.big.tiff_diroff;
 3508|      0|            ndir = 1; /* start searching from the first IFD */
 3509|      0|        }
 3510|      0|        while (1)
  ------------------
  |  Branch (3510:16): [True: 0, Folded]
  ------------------
 3511|      0|        {
 3512|      0|            uint64_t dircount64;
 3513|      0|            uint64_t nextnextdir;
 3514|       |
 3515|       |            /* Update IDF loop list and check for IFD loop. */
 3516|      0|            if (!_TIFFCheckDirNumberAndOffset(tif, ndir - 1, nextdir))
  ------------------
  |  Branch (3516:17): [True: 0, False: 0]
  ------------------
 3517|      0|            {
 3518|      0|                TIFFErrorExtR(tif, module, "Error IFD loop detected");
 3519|      0|                return 0; /* bad offset (IFD looping or more than
 3520|       |                             TIFF_MAX_DIR_COUNT IFDs) */
 3521|      0|            }
 3522|      0|            if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount64, 8))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
                          if (!SeekOK(tif, nextdir) || !ReadOK(tif, &dircount64, 8))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3522:17): [True: 0, False: 0]
  |  Branch (3522:42): [True: 0, False: 0]
  ------------------
 3523|      0|            {
 3524|      0|                TIFFErrorExtR(tif, module, "Error fetching directory count");
 3525|      0|                return (0);
 3526|      0|            }
 3527|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3527:17): [True: 0, False: 0]
  ------------------
 3528|      0|                TIFFSwabLong8(&dircount64);
 3529|      0|            if (dircount64 > 0xFFFF)
  ------------------
  |  Branch (3529:17): [True: 0, False: 0]
  ------------------
 3530|      0|            {
 3531|      0|                TIFFErrorExtR(tif, module,
 3532|      0|                              "Sanity check on tag count failed, "
 3533|      0|                              "likely corrupt TIFF");
 3534|      0|                return (0);
 3535|      0|            }
 3536|      0|            (void)TIFFSeekFile(tif, nextdir + 8 + dircount64 * 20, SEEK_SET);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3537|      0|            if (!ReadOK(tif, &nextnextdir, 8))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3537:17): [True: 0, False: 0]
  ------------------
 3538|      0|            {
 3539|      0|                TIFFErrorExtR(tif, module, "Error fetching directory link");
 3540|      0|                return (0);
 3541|      0|            }
 3542|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (3542:17): [True: 0, False: 0]
  ------------------
 3543|      0|                TIFFSwabLong8(&nextnextdir);
 3544|      0|            if (nextnextdir == 0)
  ------------------
  |  Branch (3544:17): [True: 0, False: 0]
  ------------------
 3545|      0|            {
 3546|      0|                (void)TIFFSeekFile(tif, nextdir + 8 + dircount64 * 20,
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
 3547|      0|                                   SEEK_SET);
 3548|      0|                if (!WriteOK(tif, &m, 8))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (3548:21): [True: 0, False: 0]
  ------------------
 3549|      0|                {
 3550|      0|                    TIFFErrorExtR(tif, module, "Error writing directory link");
 3551|      0|                    return (0);
 3552|      0|                }
 3553|      0|                tif->tif_lastdiroff = tif->tif_diroff;
 3554|      0|                break;
 3555|      0|            }
 3556|      0|            nextdir = nextnextdir;
 3557|      0|            ndir++;
 3558|      0|        }
 3559|      0|    }
 3560|       |    /* Offset of next IFD is written to file.
 3561|       |     * Update number of main-IFDs in file.
 3562|       |     * However, tif_curdircount shall count only newly written main-IFDs with
 3563|       |     * entries and not only number of linked offsets! Thus, tif_curdircount is
 3564|       |     * incremented at the end of TIFFWriteDirectorySec().
 3565|       |     * TIFF_NON_EXISTENT_DIR_NUMBER means 'dont know number of IFDs'
 3566|       |     * 0 means 'empty file opened for writing, but no IFD written yet' */
 3567|      0|    if (!tif->tif_dir.td_iswrittentofile && !(tif->tif_flags & TIFF_INSUBIFD))
  ------------------
  |  |  135|      0|#define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
  ------------------
  |  Branch (3567:9): [True: 0, False: 0]
  |  Branch (3567:45): [True: 0, False: 0]
  ------------------
 3568|      0|    {
 3569|      0|        tif->tif_curdircount = ndir;
 3570|      0|    }
 3571|      0|    return (1);
 3572|    170|}
tif_dirwrite.c:_WriteAsType:
 1956|    377|{
 1957|    377|    const uint16_t compression = tif->tif_dir.td_compression;
 1958|    377|    if (compression == COMPRESSION_NONE)
  ------------------
  |  |  182|    377|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
  |  Branch (1958:9): [True: 377, False: 0]
  ------------------
 1959|    377|    {
 1960|    377|        return strile_size > uncompressed_threshold;
 1961|    377|    }
 1962|      0|    else if (compression == COMPRESSION_JPEG ||
  ------------------
  |  |  190|      0|#define COMPRESSION_JPEG 7            /* %JPEG DCT compression */
  ------------------
  |  Branch (1962:14): [True: 0, False: 0]
  ------------------
 1963|      0|             compression == COMPRESSION_LZW ||
  ------------------
  |  |  188|      0|#define COMPRESSION_LZW 5             /* Lempel-Ziv  & Welch */
  ------------------
  |  Branch (1963:14): [True: 0, False: 0]
  ------------------
 1964|      0|             compression == COMPRESSION_ADOBE_DEFLATE ||
  ------------------
  |  |  206|      0|#define COMPRESSION_ADOBE_DEFLATE 8 /* Deflate compression, as recognized by Adobe */
  ------------------
  |  Branch (1964:14): [True: 0, False: 0]
  ------------------
 1965|      0|             compression == COMPRESSION_DEFLATE ||
  ------------------
  |  |  205|      0|#define COMPRESSION_DEFLATE 32946   /* Deflate compression, legacy tag */
  ------------------
  |  Branch (1965:14): [True: 0, False: 0]
  ------------------
 1966|      0|             compression == COMPRESSION_LZMA ||
  ------------------
  |  |  215|      0|#define COMPRESSION_LZMA 34925             /* LZMA2 */
  ------------------
  |  Branch (1966:14): [True: 0, False: 0]
  ------------------
 1967|      0|             compression == COMPRESSION_LERC ||
  ------------------
  |  |  213|      0|#define COMPRESSION_LERC 34887     /* ESRI Lerc codec: https://github.com/Esri/lerc */
  ------------------
  |  Branch (1967:14): [True: 0, False: 0]
  ------------------
 1968|      0|             compression == COMPRESSION_ZSTD ||
  ------------------
  |  |  216|      0|#define COMPRESSION_ZSTD 50000             /* ZSTD: WARNING not registered in Adobe-maintained registry */
  ------------------
  |  Branch (1968:14): [True: 0, False: 0]
  ------------------
 1969|      0|             compression == COMPRESSION_WEBP || compression == COMPRESSION_JXL)
  ------------------
  |  |  217|      0|#define COMPRESSION_WEBP 50001             /* WEBP: WARNING not registered in Adobe-maintained registry */
  ------------------
                           compression == COMPRESSION_WEBP || compression == COMPRESSION_JXL)
  ------------------
  |  |  218|      0|#define COMPRESSION_JXL 50002              /* JPEGXL: WARNING not registered in Adobe-maintained registry */
  ------------------
  |  Branch (1969:14): [True: 0, False: 0]
  |  Branch (1969:49): [True: 0, False: 0]
  ------------------
 1970|      0|    {
 1971|       |        /* For a few select compression types, we assume that in the worst */
 1972|       |        /* case the compressed size will be 10 times the uncompressed size. */
 1973|       |        /* This is overly pessismistic ! */
 1974|      0|        return strile_size >= uncompressed_threshold / 10;
 1975|      0|    }
 1976|      0|    return 1;
 1977|    377|}
tif_dirwrite.c:WriteAsLong4:
 1985|    377|{
 1986|    377|    return _WriteAsType(tif, strile_size, 0xFFFFU);
 1987|    377|}

TIFFInitDumpMode:
  128|    555|{
  129|    555|    (void)scheme;
  130|    555|    tif->tif_fixuptags = DumpFixupTags;
  131|    555|    tif->tif_decoderow = DumpModeDecode;
  132|    555|    tif->tif_decodestrip = DumpModeDecode;
  133|    555|    tif->tif_decodetile = DumpModeDecode;
  134|    555|    tif->tif_encoderow = DumpModeEncode;
  135|    555|    tif->tif_encodestrip = DumpModeEncode;
  136|    555|    tif->tif_encodetile = DumpModeEncode;
  137|    555|    tif->tif_seek = DumpModeSeek;
  138|    555|    return (1);
  139|    555|}

TIFFErrorExtR:
  108|     43|{
  109|     43|    va_list ap;
  110|     43|    if (tif && tif->tif_errorhandler)
  ------------------
  |  Branch (110:9): [True: 43, False: 0]
  |  Branch (110:16): [True: 0, False: 43]
  ------------------
  111|      0|    {
  112|      0|        va_start(ap, fmt);
  113|      0|        int stop = (*tif->tif_errorhandler)(
  114|      0|            tif, tif->tif_errorhandler_user_data, module, fmt, ap);
  115|      0|        va_end(ap);
  116|      0|        if (stop)
  ------------------
  |  Branch (116:13): [True: 0, False: 0]
  ------------------
  117|      0|            return;
  118|      0|    }
  119|     43|    if (_TIFFerrorHandler)
  ------------------
  |  Branch (119:9): [True: 43, False: 0]
  ------------------
  120|     43|    {
  121|     43|        va_start(ap, fmt);
  122|     43|        (*_TIFFerrorHandler)(module, fmt, ap);
  123|     43|        va_end(ap);
  124|     43|    }
  125|     43|    if (_TIFFerrorHandlerExt)
  ------------------
  |  Branch (125:9): [True: 0, False: 43]
  ------------------
  126|      0|    {
  127|      0|        va_start(ap, fmt);
  128|      0|        (*_TIFFerrorHandlerExt)(tif ? tif->tif_clientdata : NULL, module, fmt,
  ------------------
  |  Branch (128:33): [True: 0, False: 0]
  ------------------
  129|      0|                                ap);
  130|       |        va_end(ap);
  131|      0|    }
  132|     43|}

TIFFFlush:
   31|    210|{
   32|    210|    if (tif->tif_mode == O_RDONLY)
  ------------------
  |  Branch (32:9): [True: 0, False: 210]
  ------------------
   33|      0|        return 1;
   34|       |
   35|    210|    if (!TIFFFlushData(tif))
  ------------------
  |  Branch (35:9): [True: 0, False: 210]
  ------------------
   36|      0|        return (0);
   37|       |
   38|       |    /* In update (r+) mode we try to detect the case where
   39|       |       only the strip/tile map has been altered, and we try to
   40|       |       rewrite only that portion of the directory without
   41|       |       making any other changes */
   42|       |
   43|    210|    if ((tif->tif_flags & TIFF_DIRTYSTRIP) &&
  ------------------
  |  |  145|    210|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
  |  Branch (43:9): [True: 207, False: 3]
  ------------------
   44|    207|        !(tif->tif_flags & TIFF_DIRTYDIRECT) && tif->tif_mode == O_RDWR)
  ------------------
  |  |  125|    207|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
  |  Branch (44:9): [True: 0, False: 207]
  |  Branch (44:49): [True: 0, False: 0]
  ------------------
   45|      0|    {
   46|      0|        if (TIFFForceStrileArrayWriting(tif))
  ------------------
  |  Branch (46:13): [True: 0, False: 0]
  ------------------
   47|      0|            return 1;
   48|      0|    }
   49|       |
   50|    210|    if ((tif->tif_flags & (TIFF_DIRTYDIRECT | TIFF_DIRTYSTRIP)) &&
  ------------------
  |  |  125|    210|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
                  if ((tif->tif_flags & (TIFF_DIRTYDIRECT | TIFF_DIRTYSTRIP)) &&
  ------------------
  |  |  145|    210|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
  |  Branch (50:9): [True: 207, False: 3]
  ------------------
   51|    207|        !TIFFRewriteDirectory(tif))
  ------------------
  |  Branch (51:9): [True: 37, False: 170]
  ------------------
   52|     37|        return (0);
   53|       |
   54|    173|    return (1);
   55|    210|}
TIFFFlushData:
  147|    210|{
  148|    210|    if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
  ------------------
  |  |  128|    210|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
  |  Branch (148:9): [True: 3, False: 207]
  ------------------
  149|      3|        return (1);
  150|    207|    if (tif->tif_flags & TIFF_POSTENCODE)
  ------------------
  |  |  134|    207|#define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
  ------------------
  |  Branch (150:9): [True: 0, False: 207]
  ------------------
  151|      0|    {
  152|      0|        tif->tif_flags &= ~TIFF_POSTENCODE;
  ------------------
  |  |  134|      0|#define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
  ------------------
  153|      0|        if (!(*tif->tif_postencode)(tif))
  ------------------
  |  Branch (153:13): [True: 0, False: 0]
  ------------------
  154|      0|            return (0);
  155|      0|    }
  156|    207|    return (TIFFFlushData1(tif));
  157|    207|}

TIFFHashSetNew:
  152|    340|{
  153|    340|    TIFFHashSet *set = (TIFFHashSet *)_TIFFmallocExt(tif, sizeof(TIFFHashSet));
  154|    340|    if (set == NULL)
  ------------------
  |  Branch (154:9): [True: 0, False: 340]
  ------------------
  155|      0|        return NULL;
  156|    340|    set->tif = tif;
  157|    340|    set->fnHashFunc = fnHashFunc ? fnHashFunc : TIFFHashSetHashPointer;
  ------------------
  |  Branch (157:23): [True: 340, False: 0]
  ------------------
  158|    340|    set->fnEqualFunc = fnEqualFunc ? fnEqualFunc : TIFFHashSetEqualPointer;
  ------------------
  |  Branch (158:24): [True: 340, False: 0]
  ------------------
  159|    340|    set->fnFreeEltFunc = fnFreeEltFunc;
  160|    340|    set->nSize = 0;
  161|    340|    set->tabList = (TIFFList **)_TIFFcallocExt(tif, 53, sizeof(TIFFList *));
  162|    340|    if (set->tabList == NULL)
  ------------------
  |  Branch (162:9): [True: 0, False: 340]
  ------------------
  163|      0|    {
  164|      0|        _TIFFfreeExt(tif, set);
  165|      0|        return NULL;
  166|      0|    }
  167|    340|    set->nIndiceAllocatedSize = 0;
  168|    340|    set->nAllocatedSize = 53;
  169|    340|    set->psRecyclingList = NULL;
  170|    340|    set->nRecyclingListSize = 0;
  171|    340|    set->bRehash = false;
  172|       |#ifdef HASH_DEBUG
  173|       |    set->nCollisions = 0;
  174|       |#endif
  175|    340|    return set;
  176|    340|}
TIFFHashSetSize:
  193|    170|{
  194|    170|    assert(set != NULL);
  ------------------
  |  Branch (194:5): [True: 0, False: 170]
  |  Branch (194:5): [True: 170, False: 0]
  ------------------
  195|    170|    return set->nSize;
  196|    170|}
TIFFHashSetDestroy:
  299|    340|{
  300|    340|    if (set)
  ------------------
  |  Branch (300:9): [True: 340, False: 0]
  ------------------
  301|    340|    {
  302|       |        TIFFHashSetClearInternal(set, true);
  303|    340|        _TIFFfreeExt(set->tif, set->tabList);
  304|    340|        TIFFListDestroy(set->tif, set->psRecyclingList);
  305|    340|        _TIFFfreeExt(set->tif, set);
  306|    340|    }
  307|    340|}
TIFFHashSetInsert:
  455|    340|{
  456|    340|    assert(set != NULL);
  ------------------
  |  Branch (456:5): [True: 0, False: 340]
  |  Branch (456:5): [True: 340, False: 0]
  ------------------
  457|    340|    void **pElt = TIFFHashSetFindPtr(set, elt);
  458|    340|    if (pElt)
  ------------------
  |  Branch (458:9): [True: 0, False: 340]
  ------------------
  459|      0|    {
  460|      0|        if (set->fnFreeEltFunc)
  ------------------
  |  Branch (460:13): [True: 0, False: 0]
  ------------------
  461|      0|            set->fnFreeEltFunc(set->tif, *pElt);
  462|       |
  463|      0|        *pElt = elt;
  464|      0|        return true;
  465|      0|    }
  466|       |
  467|    340|    if (set->nSize >= 2 * set->nAllocatedSize / 3 ||
  ------------------
  |  Branch (467:9): [True: 0, False: 340]
  ------------------
  468|    340|        (set->bRehash && set->nIndiceAllocatedSize > 0 &&
  ------------------
  |  Branch (468:10): [True: 0, False: 340]
  |  Branch (468:26): [True: 0, False: 0]
  ------------------
  469|      0|         set->nSize <= set->nAllocatedSize / 2))
  ------------------
  |  Branch (469:10): [True: 0, False: 0]
  ------------------
  470|      0|    {
  471|      0|        set->nIndiceAllocatedSize++;
  472|      0|        if (!TIFFHashSetRehash(set))
  ------------------
  |  Branch (472:13): [True: 0, False: 0]
  ------------------
  473|      0|        {
  474|      0|            set->nIndiceAllocatedSize--;
  475|      0|            if (set->fnFreeEltFunc)
  ------------------
  |  Branch (475:17): [True: 0, False: 0]
  ------------------
  476|      0|                set->fnFreeEltFunc(set->tif, elt);
  477|      0|            return false;
  478|      0|        }
  479|      0|    }
  480|       |
  481|    340|    const unsigned long nHashVal =
  482|    340|        set->fnHashFunc(elt) % (unsigned long)set->nAllocatedSize;
  483|       |#ifdef HASH_DEBUG
  484|       |    if (set->tabList[nHashVal])
  485|       |        set->nCollisions++;
  486|       |#endif
  487|       |
  488|    340|    TIFFList *new_elt = TIFFHashSetGetNewListElt(set);
  489|    340|    if (new_elt == NULL)
  ------------------
  |  Branch (489:9): [True: 0, False: 340]
  ------------------
  490|      0|    {
  491|      0|        if (set->fnFreeEltFunc)
  ------------------
  |  Branch (491:13): [True: 0, False: 0]
  ------------------
  492|      0|            set->fnFreeEltFunc(set->tif, elt);
  493|      0|        return false;
  494|      0|    }
  495|    340|    new_elt->pData = elt;
  496|    340|    new_elt->psNext = set->tabList[nHashVal];
  497|    340|    set->tabList[nHashVal] = new_elt;
  498|    340|    set->nSize++;
  499|       |
  500|       |    return true;
  501|    340|}
TIFFHashSetLookup:
  518|    340|{
  519|    340|    assert(set != NULL);
  ------------------
  |  Branch (519:5): [True: 0, False: 340]
  |  Branch (519:5): [True: 340, False: 0]
  ------------------
  520|    340|    void **pElt = TIFFHashSetFindPtr(set, elt);
  521|    340|    if (pElt)
  ------------------
  |  Branch (521:9): [True: 0, False: 340]
  ------------------
  522|      0|        return *pElt;
  523|       |
  524|    340|    return NULL;
  525|    340|}
tif_hash_set.c:TIFFHashSetClearInternal:
  239|    340|{
  240|    340|    assert(set != NULL);
  ------------------
  |  Branch (240:5): [True: 0, False: 340]
  |  Branch (240:5): [True: 340, False: 0]
  ------------------
  241|  18.3k|    for (int i = 0; i < set->nAllocatedSize; i++)
  ------------------
  |  Branch (241:21): [True: 18.0k, False: 340]
  ------------------
  242|  18.0k|    {
  243|  18.0k|        TIFFList *cur = set->tabList[i];
  244|  18.3k|        while (cur)
  ------------------
  |  Branch (244:16): [True: 340, False: 18.0k]
  ------------------
  245|    340|        {
  246|    340|            if (set->fnFreeEltFunc)
  ------------------
  |  Branch (246:17): [True: 170, False: 170]
  ------------------
  247|    170|                set->fnFreeEltFunc(set->tif, cur->pData);
  248|    340|            TIFFList *psNext = cur->psNext;
  249|    340|            if (bFinalize)
  ------------------
  |  Branch (249:17): [True: 340, False: 0]
  ------------------
  250|    340|                _TIFFfreeExt(set->tif, cur);
  251|      0|            else
  252|      0|                TIFFHashSetReturnListElt(set, cur);
  253|    340|            cur = psNext;
  254|    340|        }
  255|  18.0k|        set->tabList[i] = NULL;
  256|  18.0k|    }
  257|       |    set->bRehash = false;
  258|    340|}
tif_hash_set.c:TIFFListDestroy:
  274|    340|{
  275|    340|    TIFFList *psCurrent = psList;
  276|       |
  277|    340|    while (psCurrent)
  ------------------
  |  Branch (277:12): [True: 0, False: 340]
  ------------------
  278|      0|    {
  279|      0|        TIFFList *const psNext = psCurrent->psNext;
  280|      0|        _TIFFfreeExt(tif, psCurrent);
  281|      0|        psCurrent = psNext;
  282|      0|    }
  283|    340|}
tif_hash_set.c:TIFFHashSetFindPtr:
  423|    680|{
  424|    680|    const unsigned long nHashVal =
  425|    680|        set->fnHashFunc(elt) % (unsigned long)set->nAllocatedSize;
  426|    680|    TIFFList *cur = set->tabList[nHashVal];
  427|    680|    while (cur)
  ------------------
  |  Branch (427:12): [True: 0, False: 680]
  ------------------
  428|      0|    {
  429|      0|        if (set->fnEqualFunc(cur->pData, elt))
  ------------------
  |  Branch (429:13): [True: 0, False: 0]
  ------------------
  430|      0|            return &cur->pData;
  431|      0|        cur = cur->psNext;
  432|      0|    }
  433|    680|    return NULL;
  434|    680|}
tif_hash_set.c:TIFFHashSetGetNewListElt:
  203|    340|{
  204|    340|    if (set->psRecyclingList)
  ------------------
  |  Branch (204:9): [True: 0, False: 340]
  ------------------
  205|      0|    {
  206|      0|        TIFFList *psRet = set->psRecyclingList;
  207|      0|        psRet->pData = NULL;
  208|      0|        set->nRecyclingListSize--;
  209|      0|        set->psRecyclingList = psRet->psNext;
  210|      0|        return psRet;
  211|      0|    }
  212|       |
  213|    340|    return (TIFFList *)_TIFFmallocExt(set->tif, sizeof(TIFFList));
  214|    340|}

_TIFFgetMode:
   57|    420|{
   58|    420|    int m = -1;
   59|       |
   60|    420|    switch (mode[0])
   61|    420|    {
   62|      0|        case 'r':
  ------------------
  |  Branch (62:9): [True: 0, False: 420]
  ------------------
   63|      0|            m = O_RDONLY;
   64|      0|            if (mode[1] == '+')
  ------------------
  |  Branch (64:17): [True: 0, False: 0]
  ------------------
   65|      0|                m = O_RDWR;
   66|      0|            break;
   67|    420|        case 'w':
  ------------------
  |  Branch (67:9): [True: 420, False: 0]
  ------------------
   68|    420|        case 'a':
  ------------------
  |  Branch (68:9): [True: 0, False: 420]
  ------------------
   69|    420|            m = O_RDWR | O_CREAT;
   70|    420|            if (mode[0] == 'w')
  ------------------
  |  Branch (70:17): [True: 420, False: 0]
  ------------------
   71|    420|                m |= O_TRUNC;
   72|    420|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 420]
  ------------------
   74|      0|            _TIFFErrorEarly(opts, clientdata, module, "\"%s\": Bad mode", mode);
   75|      0|            break;
   76|    420|    }
   77|    420|    return (m);
   78|    420|}
_TIFFmallocExt:
  174|  1.43k|{
  175|  1.43k|    if (s <= 0)
  ------------------
  |  Branch (175:9): [True: 0, False: 1.43k]
  ------------------
  176|      0|        return NULL;
  177|  1.43k|    if (tif != NULL && tif->tif_max_single_mem_alloc > 0 &&
  ------------------
  |  Branch (177:9): [True: 1.22k, False: 210]
  |  Branch (177:24): [True: 0, False: 1.22k]
  ------------------
  178|      0|        s > tif->tif_max_single_mem_alloc)
  ------------------
  |  Branch (178:9): [True: 0, False: 0]
  ------------------
  179|      0|    {
  180|      0|        _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFmallocExt", s);
  181|      0|        return NULL;
  182|      0|    }
  183|  1.43k|    if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
  ------------------
  |  Branch (183:9): [True: 1.22k, False: 210]
  |  Branch (183:24): [True: 0, False: 1.22k]
  ------------------
  184|      0|    {
  185|      0|        if (s > tif->tif_max_cumulated_mem_alloc -
  ------------------
  |  Branch (185:13): [True: 0, False: 0]
  ------------------
  186|      0|                    tif->tif_cur_cumulated_mem_alloc ||
  187|      0|            s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE)
  ------------------
  |  |   68|      0|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
                          s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE)
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  |  Branch (187:13): [True: 0, False: 0]
  ------------------
  188|      0|        {
  189|      0|            _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFmallocExt", s);
  190|      0|            return NULL;
  191|      0|        }
  192|      0|        void *ptr = _TIFFmalloc(LEADING_AREA_TO_STORE_ALLOC_SIZE + s);
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  193|      0|        if (!ptr)
  ------------------
  |  Branch (193:13): [True: 0, False: 0]
  ------------------
  194|      0|            return NULL;
  195|      0|        tif->tif_cur_cumulated_mem_alloc += s;
  196|      0|        memcpy(ptr, &s, sizeof(s));
  197|      0|        return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  198|      0|    }
  199|  1.43k|    return _TIFFmalloc(s);
  200|  1.43k|}
_TIFFcallocExt:
  204|    340|{
  205|    340|    if (nmemb <= 0 || siz <= 0 || nmemb > TIFF_TMSIZE_T_MAX / siz)
  ------------------
  |  |   68|    340|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
  |  Branch (205:9): [True: 0, False: 340]
  |  Branch (205:23): [True: 0, False: 340]
  |  Branch (205:35): [True: 0, False: 340]
  ------------------
  206|      0|        return NULL;
  207|    340|    if (tif != NULL && tif->tif_max_single_mem_alloc > 0)
  ------------------
  |  Branch (207:9): [True: 340, False: 0]
  |  Branch (207:24): [True: 0, False: 340]
  ------------------
  208|      0|    {
  209|      0|        if (nmemb * siz > tif->tif_max_single_mem_alloc)
  ------------------
  |  Branch (209:13): [True: 0, False: 0]
  ------------------
  210|      0|        {
  211|      0|            _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFcallocExt",
  212|      0|                                                 nmemb * siz);
  213|      0|            return NULL;
  214|      0|        }
  215|      0|    }
  216|    340|    if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
  ------------------
  |  Branch (216:9): [True: 340, False: 0]
  |  Branch (216:24): [True: 0, False: 340]
  ------------------
  217|      0|    {
  218|      0|        const tmsize_t s = nmemb * siz;
  219|      0|        if (s > tif->tif_max_cumulated_mem_alloc -
  ------------------
  |  Branch (219:13): [True: 0, False: 0]
  ------------------
  220|      0|                    tif->tif_cur_cumulated_mem_alloc ||
  221|      0|            s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE)
  ------------------
  |  |   68|      0|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
                          s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE)
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  |  Branch (221:13): [True: 0, False: 0]
  ------------------
  222|      0|        {
  223|      0|            _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFcallocExt", s);
  224|      0|            return NULL;
  225|      0|        }
  226|      0|        void *ptr = _TIFFcalloc(LEADING_AREA_TO_STORE_ALLOC_SIZE + s, 1);
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  227|      0|        if (!ptr)
  ------------------
  |  Branch (227:13): [True: 0, False: 0]
  ------------------
  228|      0|            return NULL;
  229|      0|        tif->tif_cur_cumulated_mem_alloc += s;
  230|      0|        memcpy(ptr, &s, sizeof(s));
  231|      0|        return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  232|      0|    }
  233|    340|    return _TIFFcalloc(nmemb, siz);
  234|    340|}
_TIFFreallocExt:
  238|  1.85k|{
  239|  1.85k|    if (s <= 0)
  ------------------
  |  Branch (239:9): [True: 0, False: 1.85k]
  ------------------
  240|      0|    {
  241|      0|        _TIFFfreeExt(tif, p);
  242|      0|        return NULL;
  243|      0|    }
  244|  1.85k|    if (tif != NULL && tif->tif_max_single_mem_alloc > 0 &&
  ------------------
  |  Branch (244:9): [True: 1.85k, False: 0]
  |  Branch (244:24): [True: 0, False: 1.85k]
  ------------------
  245|      0|        s > tif->tif_max_single_mem_alloc)
  ------------------
  |  Branch (245:9): [True: 0, False: 0]
  ------------------
  246|      0|    {
  247|      0|        _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFreallocExt", s);
  248|      0|        return NULL;
  249|      0|    }
  250|  1.85k|    if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
  ------------------
  |  Branch (250:9): [True: 1.85k, False: 0]
  |  Branch (250:24): [True: 0, False: 1.85k]
  ------------------
  251|      0|    {
  252|      0|        void *oldPtr = p;
  253|      0|        tmsize_t oldSize = 0;
  254|      0|        if (p)
  ------------------
  |  Branch (254:13): [True: 0, False: 0]
  ------------------
  255|      0|        {
  256|      0|            oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE;
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  257|      0|            memcpy(&oldSize, oldPtr, sizeof(oldSize));
  258|      0|            assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
  ------------------
  |  Branch (258:13): [True: 0, False: 0]
  |  Branch (258:13): [True: 0, False: 0]
  ------------------
  259|      0|        }
  260|      0|        if (s > oldSize &&
  ------------------
  |  Branch (260:13): [True: 0, False: 0]
  ------------------
  261|      0|            (s > tif->tif_max_cumulated_mem_alloc -
  ------------------
  |  Branch (261:14): [True: 0, False: 0]
  ------------------
  262|      0|                     (tif->tif_cur_cumulated_mem_alloc - oldSize) ||
  263|      0|             s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE))
  ------------------
  |  |   68|      0|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
                           s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE))
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  |  Branch (263:14): [True: 0, False: 0]
  ------------------
  264|      0|        {
  265|      0|            _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFreallocExt",
  266|      0|                                                    s - oldSize);
  267|      0|            return NULL;
  268|      0|        }
  269|      0|        void *newPtr =
  270|      0|            _TIFFrealloc(oldPtr, LEADING_AREA_TO_STORE_ALLOC_SIZE + s);
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  271|      0|        if (newPtr == NULL)
  ------------------
  |  Branch (271:13): [True: 0, False: 0]
  ------------------
  272|      0|            return NULL;
  273|      0|        tif->tif_cur_cumulated_mem_alloc -= oldSize;
  274|      0|        tif->tif_cur_cumulated_mem_alloc += s;
  275|      0|        memcpy(newPtr, &s, sizeof(s));
  276|      0|        return (char *)newPtr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  277|      0|    }
  278|  1.85k|    return _TIFFrealloc(p, s);
  279|  1.85k|}
_TIFFfreeExt:
  283|  3.62k|{
  284|  3.62k|    if (p != NULL && tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
  ------------------
  |  Branch (284:9): [True: 3.62k, False: 0]
  |  Branch (284:22): [True: 3.41k, False: 210]
  |  Branch (284:37): [True: 0, False: 3.41k]
  ------------------
  285|      0|    {
  286|      0|        void *oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE;
  ------------------
  |  |  170|      0|#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
  |  |  ------------------
  |  |  |  |  116|      0|#define SIZEOF_SIZE_T 8
  |  |  ------------------
  ------------------
  287|      0|        tmsize_t oldSize;
  288|      0|        memcpy(&oldSize, oldPtr, sizeof(oldSize));
  289|      0|        assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
  ------------------
  |  Branch (289:9): [True: 0, False: 0]
  |  Branch (289:9): [True: 0, False: 0]
  ------------------
  290|      0|        tif->tif_cur_cumulated_mem_alloc -= oldSize;
  291|      0|        p = oldPtr;
  292|      0|    }
  293|  3.62k|    _TIFFfree(p);
  294|  3.62k|}
TIFFClientOpenExt:
  313|    210|{
  314|    210|    static const char module[] = "TIFFClientOpenExt";
  315|    210|    TIFF *tif;
  316|    210|    int m;
  317|    210|    const char *cp;
  318|    210|    size_t name_len;
  319|    210|    tmsize_t size_to_alloc;
  320|       |
  321|       |    /* The following are configuration checks. They should be redundant, but
  322|       |     * should not compile to any actual code in an optimised release build
  323|       |     * anyway. If any of them fail, (makefile-based or other) configuration is
  324|       |     * not correct */
  325|    210|    assert(sizeof(uint8_t) == 1);
  ------------------
  |  Branch (325:5): [True: 0, Folded]
  |  Branch (325:5): [True: 210, Folded]
  ------------------
  326|    210|    assert(sizeof(int8_t) == 1);
  ------------------
  |  Branch (326:5): [True: 0, Folded]
  |  Branch (326:5): [True: 210, Folded]
  ------------------
  327|    210|    assert(sizeof(uint16_t) == 2);
  ------------------
  |  Branch (327:5): [True: 0, Folded]
  |  Branch (327:5): [True: 210, Folded]
  ------------------
  328|    210|    assert(sizeof(int16_t) == 2);
  ------------------
  |  Branch (328:5): [True: 0, Folded]
  |  Branch (328:5): [True: 210, Folded]
  ------------------
  329|    210|    assert(sizeof(uint32_t) == 4);
  ------------------
  |  Branch (329:5): [True: 0, Folded]
  |  Branch (329:5): [True: 210, Folded]
  ------------------
  330|    210|    assert(sizeof(int32_t) == 4);
  ------------------
  |  Branch (330:5): [True: 0, Folded]
  |  Branch (330:5): [True: 210, Folded]
  ------------------
  331|    210|    assert(sizeof(uint64_t) == 8);
  ------------------
  |  Branch (331:5): [True: 0, Folded]
  |  Branch (331:5): [True: 210, Folded]
  ------------------
  332|    210|    assert(sizeof(int64_t) == 8);
  ------------------
  |  Branch (332:5): [True: 0, Folded]
  |  Branch (332:5): [True: 210, Folded]
  ------------------
  333|    210|    {
  334|    210|        union
  335|    210|        {
  336|    210|            uint8_t a8[2];
  337|    210|            uint16_t a16;
  338|    210|        } n;
  339|    210|        n.a8[0] = 1;
  340|    210|        n.a8[1] = 0;
  341|    210|        (void)n;
  342|       |#if WORDS_BIGENDIAN
  343|       |        assert(n.a16 == 256);
  344|       |#else
  345|    210|        assert(n.a16 == 1);
  ------------------
  |  Branch (345:9): [True: 0, False: 210]
  |  Branch (345:9): [True: 210, False: 0]
  ------------------
  346|    210|#endif
  347|    210|    }
  348|       |
  349|    210|    m = _TIFFgetMode(opts, clientdata, mode, module);
  350|    210|    if (m == -1)
  ------------------
  |  Branch (350:9): [True: 0, False: 210]
  ------------------
  351|      0|        goto bad2;
  352|       |    /* Keep the length used for the allocation and the one used for the copy
  353|       |     * in a single variable, so they cannot drift apart. */
  354|    210|    name_len = strlen(name) + 1;
  355|    210|    size_to_alloc = (tmsize_t)(sizeof(TIFF) + name_len);
  356|    210|    if (opts && opts->max_single_mem_alloc > 0 &&
  ------------------
  |  Branch (356:9): [True: 0, False: 210]
  |  Branch (356:17): [True: 0, False: 0]
  ------------------
  357|      0|        size_to_alloc > opts->max_single_mem_alloc)
  ------------------
  |  Branch (357:9): [True: 0, False: 0]
  ------------------
  358|      0|    {
  359|      0|        _TIFFErrorEarly(opts, clientdata, module,
  360|      0|                        "%s: Memory allocation of %" PRIu64
  361|      0|                        " bytes is beyond the %" PRIu64
  362|      0|                        " byte limit defined in open options",
  363|      0|                        name, (uint64_t)size_to_alloc,
  364|      0|                        (uint64_t)opts->max_single_mem_alloc);
  365|      0|        goto bad2;
  366|      0|    }
  367|    210|    if (opts && opts->max_cumulated_mem_alloc > 0 &&
  ------------------
  |  Branch (367:9): [True: 0, False: 210]
  |  Branch (367:17): [True: 0, False: 0]
  ------------------
  368|      0|        size_to_alloc > opts->max_cumulated_mem_alloc)
  ------------------
  |  Branch (368:9): [True: 0, False: 0]
  ------------------
  369|      0|    {
  370|      0|        _TIFFErrorEarly(opts, clientdata, module,
  371|      0|                        "%s: Memory allocation of %" PRIu64
  372|      0|                        " bytes is beyond the %" PRIu64
  373|      0|                        " cumulated byte limit defined in open options",
  374|      0|                        name, (uint64_t)size_to_alloc,
  375|      0|                        (uint64_t)opts->max_cumulated_mem_alloc);
  376|      0|        goto bad2;
  377|      0|    }
  378|    210|    tif = (TIFF *)_TIFFmallocExt(NULL, size_to_alloc);
  379|    210|    if (tif == NULL)
  ------------------
  |  Branch (379:9): [True: 0, False: 210]
  ------------------
  380|      0|    {
  381|      0|        _TIFFErrorEarly(opts, clientdata, module,
  382|      0|                        "%s: Out of memory (TIFF structure)", name);
  383|      0|        goto bad2;
  384|      0|    }
  385|    210|    _TIFFmemset(tif, 0, sizeof(*tif));
  386|    210|    tif->tif_name = (char *)tif + sizeof(TIFF);
  387|    210|    _TIFFmemcpy(tif->tif_name, name, (tmsize_t)name_len);
  388|    210|    tif->tif_mode = m & ~(O_CREAT | O_TRUNC);
  389|    210|    tif->tif_curdir = TIFF_NON_EXISTENT_DIR_NUMBER; /* non-existent directory */
  ------------------
  |  |   68|    210|#define TIFF_NON_EXISTENT_DIR_NUMBER UINT_MAX
  ------------------
  390|    210|    tif->tif_curdircount = TIFF_NON_EXISTENT_DIR_NUMBER;
  ------------------
  |  |   68|    210|#define TIFF_NON_EXISTENT_DIR_NUMBER UINT_MAX
  ------------------
  391|    210|    tif->tif_curoff = 0;
  392|    210|    tif->tif_clientdata = clientdata;
  393|    210|    tif->tif_readproc = readproc;
  394|    210|    tif->tif_writeproc = writeproc;
  395|    210|    tif->tif_seekproc = seekproc;
  396|    210|    tif->tif_closeproc = closeproc;
  397|    210|    tif->tif_sizeproc = sizeproc;
  398|    210|    tif->tif_mapproc = mapproc ? mapproc : _tiffDummyMapProc;
  ------------------
  |  Branch (398:24): [True: 210, False: 0]
  ------------------
  399|    210|    tif->tif_unmapproc = unmapproc ? unmapproc : _tiffDummyUnmapProc;
  ------------------
  |  Branch (399:26): [True: 210, False: 0]
  ------------------
  400|    210|    if (opts)
  ------------------
  |  Branch (400:9): [True: 0, False: 210]
  ------------------
  401|      0|    {
  402|      0|        tif->tif_errorhandler = opts->errorhandler;
  403|      0|        tif->tif_errorhandler_user_data = opts->errorhandler_user_data;
  404|      0|        tif->tif_warnhandler = opts->warnhandler;
  405|      0|        tif->tif_warnhandler_user_data = opts->warnhandler_user_data;
  406|      0|        tif->tif_max_single_mem_alloc = opts->max_single_mem_alloc;
  407|      0|        tif->tif_max_cumulated_mem_alloc = opts->max_cumulated_mem_alloc;
  408|      0|        tif->tif_warn_about_unknown_tags = opts->warn_about_unknown_tags;
  409|      0|    }
  410|       |
  411|       |    /* Reset tif->tif_dir structure to zero and
  412|       |     * initialize some IFD strile counter and index parameters. */
  413|    210|    _TIFFResetTifDirAndInitStrileCounters(&tif->tif_dir);
  414|       |
  415|    210|    if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc)
  ------------------
  |  Branch (415:9): [True: 0, False: 210]
  |  Branch (415:22): [True: 0, False: 210]
  |  Branch (415:36): [True: 0, False: 210]
  |  Branch (415:49): [True: 0, False: 210]
  |  Branch (415:63): [True: 0, False: 210]
  ------------------
  416|      0|    {
  417|      0|        TIFFErrorExtR(tif, module,
  418|      0|                      "One of the client procedures is NULL pointer.");
  419|      0|        _TIFFfreeExt(NULL, tif);
  420|      0|        goto bad2;
  421|      0|    }
  422|       |
  423|    210|    _TIFFSetDefaultCompressionState(tif); /* setup default state */
  424|       |    /*
  425|       |     * Default is to return data MSB2LSB and enable the
  426|       |     * use of memory-mapped files and strip chopping when
  427|       |     * a file is opened read-only.
  428|       |     */
  429|    210|    tif->tif_flags = FILLORDER_MSB2LSB;
  ------------------
  |  |  241|    210|#define FILLORDER_MSB2LSB 1                /* most significant -> least */
  ------------------
  430|    210|    if (m == O_RDONLY)
  ------------------
  |  Branch (430:9): [True: 0, False: 210]
  ------------------
  431|      0|        tif->tif_flags |= TIFF_MAPPED;
  ------------------
  |  |  133|      0|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  ------------------
  432|       |
  433|    210|#ifdef STRIPCHOP_DEFAULT
  434|    210|    if (m == O_RDONLY || m == O_RDWR)
  ------------------
  |  Branch (434:9): [True: 0, False: 210]
  |  Branch (434:26): [True: 0, False: 210]
  ------------------
  435|      0|        tif->tif_flags |= STRIPCHOP_DEFAULT;
  ------------------
  |  |  113|      0|#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP
  |  |  ------------------
  |  |  |  |  137|      0|#define TIFF_STRIPCHOP 0x08000U   /* enable strip chopping support */
  |  |  ------------------
  ------------------
  436|    210|#endif
  437|       |
  438|       |    /*
  439|       |     * Process library-specific flags in the open mode string.
  440|       |     * The following flags may be used to control intrinsic library
  441|       |     * behavior that may or may not be desirable (usually for
  442|       |     * compatibility with some application that claims to support
  443|       |     * TIFF but only supports some brain dead idea of what the
  444|       |     * vendor thinks TIFF is):
  445|       |     *
  446|       |     * 'l' use little-endian byte order for creating a file
  447|       |     * 'b' use big-endian byte order for creating a file
  448|       |     * 'L' read/write information using LSB2MSB bit order
  449|       |     * 'B' read/write information using MSB2LSB bit order
  450|       |     * 'H' read/write information using host bit order
  451|       |     * 'M' enable use of memory-mapped files when supported
  452|       |     * 'm' disable use of memory-mapped files
  453|       |     * 'C' enable strip chopping support when reading
  454|       |     * 'c' disable strip chopping support
  455|       |     * 'h' read TIFF header only, do not load the first IFD
  456|       |     * '4' ClassicTIFF for creating a file (default)
  457|       |     * '8' BigTIFF for creating a file
  458|       |     * 'D' enable use of deferred strip/tile offset/bytecount array loading.
  459|       |     * 'O' on-demand loading of values instead of whole array loading (implies
  460|       |     * D)
  461|       |     *
  462|       |     * The use of the 'l' and 'b' flags is strongly discouraged.
  463|       |     * These flags are provided solely because numerous vendors,
  464|       |     * typically on the PC, do not correctly support TIFF; they
  465|       |     * only support the Intel little-endian byte order.  This
  466|       |     * support is not configured by default because it supports
  467|       |     * the violation of the TIFF spec that says that readers *MUST*
  468|       |     * support both byte orders.  It is strongly recommended that
  469|       |     * you not use this feature except to deal with busted apps
  470|       |     * that write invalid TIFF.  And even in those cases you should
  471|       |     * bang on the vendors to fix their software.
  472|       |     *
  473|       |     * The 'L', 'B', and 'H' flags are intended for applications
  474|       |     * that can optimize operations on data by using a particular
  475|       |     * bit order.  By default the library returns data in MSB2LSB
  476|       |     * bit order for compatibility with older versions of this
  477|       |     * library.  Returning data in the bit order of the native CPU
  478|       |     * makes the most sense but also requires applications to check
  479|       |     * the value of the FillOrder tag; something they probably do
  480|       |     * not do right now.
  481|       |     *
  482|       |     * The 'M' and 'm' flags are provided because some virtual memory
  483|       |     * systems exhibit poor behavior when large images are mapped.
  484|       |     * These options permit clients to control the use of memory-mapped
  485|       |     * files on a per-file basis.
  486|       |     *
  487|       |     * The 'C' and 'c' flags are provided because the library support
  488|       |     * for chopping up large strips into multiple smaller strips is not
  489|       |     * application-transparent and as such can cause problems.  The 'c'
  490|       |     * option permits applications that only want to look at the tags,
  491|       |     * for example, to get the unadulterated TIFF tag information.
  492|       |     */
  493|    420|    for (cp = mode; *cp; cp++)
  ------------------
  |  Branch (493:21): [True: 210, False: 210]
  ------------------
  494|    210|        switch (*cp)
  495|    210|        {
  496|      0|            case 'b':
  ------------------
  |  Branch (496:13): [True: 0, False: 210]
  ------------------
  497|      0|#if !WORDS_BIGENDIAN
  498|      0|                if (m & O_CREAT)
  ------------------
  |  Branch (498:21): [True: 0, False: 0]
  ------------------
  499|      0|                    tif->tif_flags |= TIFF_SWAB;
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  500|      0|#endif
  501|      0|                break;
  502|      0|            case 'l':
  ------------------
  |  Branch (502:13): [True: 0, False: 210]
  ------------------
  503|       |#if WORDS_BIGENDIAN
  504|       |                if ((m & O_CREAT))
  505|       |                    tif->tif_flags |= TIFF_SWAB;
  506|       |#endif
  507|      0|                break;
  508|      0|            case 'B':
  ------------------
  |  Branch (508:13): [True: 0, False: 210]
  ------------------
  509|      0|                tif->tif_flags =
  510|      0|                    (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
  ------------------
  |  |  123|      0|#define TIFF_FILLORDER 0x00003U   /* natural bit fill order for machine */
  ------------------
                                  (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
  ------------------
  |  |  241|      0|#define FILLORDER_MSB2LSB 1                /* most significant -> least */
  ------------------
  511|      0|                break;
  512|      0|            case 'L':
  ------------------
  |  Branch (512:13): [True: 0, False: 210]
  ------------------
  513|      0|                tif->tif_flags =
  514|      0|                    (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_LSB2MSB;
  ------------------
  |  |  123|      0|#define TIFF_FILLORDER 0x00003U   /* natural bit fill order for machine */
  ------------------
                                  (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_LSB2MSB;
  ------------------
  |  |  242|      0|#define FILLORDER_LSB2MSB 2                /* least significant -> most */
  ------------------
  515|      0|                break;
  516|      0|            case 'H':
  ------------------
  |  Branch (516:13): [True: 0, False: 210]
  ------------------
  517|      0|                TIFFWarningExtR(tif, name,
  518|      0|                                "H(ost) mode is deprecated. Since "
  519|      0|                                "libtiff 4.5.1, it is an alias of 'B' / "
  520|      0|                                "FILLORDER_MSB2LSB.");
  521|      0|                tif->tif_flags =
  522|      0|                    (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
  ------------------
  |  |  123|      0|#define TIFF_FILLORDER 0x00003U   /* natural bit fill order for machine */
  ------------------
                                  (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
  ------------------
  |  |  241|      0|#define FILLORDER_MSB2LSB 1                /* most significant -> least */
  ------------------
  523|      0|                break;
  524|      0|            case 'M':
  ------------------
  |  Branch (524:13): [True: 0, False: 210]
  ------------------
  525|      0|                if (m == O_RDONLY)
  ------------------
  |  Branch (525:21): [True: 0, False: 0]
  ------------------
  526|      0|                    tif->tif_flags |= TIFF_MAPPED;
  ------------------
  |  |  133|      0|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  ------------------
  527|      0|                break;
  528|      0|            case 'm':
  ------------------
  |  Branch (528:13): [True: 0, False: 210]
  ------------------
  529|      0|                if (m == O_RDONLY)
  ------------------
  |  Branch (529:21): [True: 0, False: 0]
  ------------------
  530|      0|                    tif->tif_flags &= ~TIFF_MAPPED;
  ------------------
  |  |  133|      0|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  ------------------
  531|      0|                break;
  532|      0|            case 'C':
  ------------------
  |  Branch (532:13): [True: 0, False: 210]
  ------------------
  533|      0|                if (m == O_RDONLY)
  ------------------
  |  Branch (533:21): [True: 0, False: 0]
  ------------------
  534|      0|                    tif->tif_flags |= TIFF_STRIPCHOP;
  ------------------
  |  |  137|      0|#define TIFF_STRIPCHOP 0x08000U   /* enable strip chopping support */
  ------------------
  535|      0|                break;
  536|      0|            case 'c':
  ------------------
  |  Branch (536:13): [True: 0, False: 210]
  ------------------
  537|      0|                if (m == O_RDONLY)
  ------------------
  |  Branch (537:21): [True: 0, False: 0]
  ------------------
  538|      0|                    tif->tif_flags &= ~TIFF_STRIPCHOP;
  ------------------
  |  |  137|      0|#define TIFF_STRIPCHOP 0x08000U   /* enable strip chopping support */
  ------------------
  539|      0|                break;
  540|      0|            case 'h':
  ------------------
  |  Branch (540:13): [True: 0, False: 210]
  ------------------
  541|      0|                tif->tif_flags |= TIFF_HEADERONLY;
  ------------------
  |  |  139|      0|    0x10000U /* read header only, do not process the first directory */
  ------------------
  542|      0|                break;
  543|      0|            case '8':
  ------------------
  |  Branch (543:13): [True: 0, False: 210]
  ------------------
  544|      0|                if (m & O_CREAT)
  ------------------
  |  Branch (544:21): [True: 0, False: 0]
  ------------------
  545|      0|                    tif->tif_flags |= TIFF_BIGTIFF;
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  546|      0|                break;
  547|      0|            case 'D':
  ------------------
  |  Branch (547:13): [True: 0, False: 210]
  ------------------
  548|      0|                tif->tif_flags |= TIFF_DEFERSTRILELOAD;
  ------------------
  |  |  150|      0|    0x1000000U /* defer strip/tile offset/bytecount array loading. */
  ------------------
  549|      0|                break;
  550|      0|            case 'O':
  ------------------
  |  Branch (550:13): [True: 0, False: 210]
  ------------------
  551|      0|                if (m == O_RDONLY)
  ------------------
  |  Branch (551:21): [True: 0, False: 0]
  ------------------
  552|      0|                    tif->tif_flags |=
  553|      0|                        (TIFF_LAZYSTRILELOAD_ASKED | TIFF_DEFERSTRILELOAD);
  ------------------
  |  |  159|      0|    0x8000000U /* set when lazy/ondemand loading of strip/tile                 \
  ------------------
                                      (TIFF_LAZYSTRILELOAD_ASKED | TIFF_DEFERSTRILELOAD);
  ------------------
  |  |  150|      0|    0x1000000U /* defer strip/tile offset/bytecount array loading. */
  ------------------
  554|      0|                break;
  555|    210|            default:
  ------------------
  |  Branch (555:13): [True: 210, False: 0]
  ------------------
  556|    210|                break;
  557|    210|        }
  558|       |
  559|       |#ifdef DEFER_STRILE_LOAD
  560|       |    /* Compatibility with old DEFER_STRILE_LOAD compilation flag */
  561|       |    /* Probably unneeded, since to the best of my knowledge (E. Rouault) */
  562|       |    /* GDAL was the only user of this, and will now use the new 'D' flag */
  563|       |    tif->tif_flags |= TIFF_DEFERSTRILELOAD;
  564|       |#endif
  565|       |
  566|       |    /*
  567|       |     * Read in TIFF header.
  568|       |     */
  569|    210|    if ((m & O_TRUNC) ||
  ------------------
  |  Branch (569:9): [True: 210, False: 0]
  ------------------
  570|      0|        !ReadOK(tif, &tif->tif_header, sizeof(TIFFHeaderClassic)))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (570:9): [True: 0, False: 0]
  ------------------
  571|    210|    {
  572|    210|        if (tif->tif_mode == O_RDONLY)
  ------------------
  |  Branch (572:13): [True: 0, False: 210]
  ------------------
  573|      0|        {
  574|      0|            TIFFErrorExtR(tif, name, "Cannot read TIFF header");
  575|      0|            goto bad;
  576|      0|        }
  577|       |        /*
  578|       |         * Setup header and write.
  579|       |         */
  580|       |#if WORDS_BIGENDIAN
  581|       |        tif->tif_header.common.tiff_magic =
  582|       |            (tif->tif_flags & TIFF_SWAB) ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN;
  583|       |#else
  584|    210|        tif->tif_header.common.tiff_magic =
  585|    210|            (tif->tif_flags & TIFF_SWAB) ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
  ------------------
  |  |  129|    210|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
                          (tif->tif_flags & TIFF_SWAB) ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
  ------------------
  |  |   51|      0|#define TIFF_BIGENDIAN 0x4d4d
  ------------------
                          (tif->tif_flags & TIFF_SWAB) ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
  ------------------
  |  |   52|    420|#define TIFF_LITTLEENDIAN 0x4949
  ------------------
  |  Branch (585:13): [True: 0, False: 210]
  ------------------
  586|    210|#endif
  587|    210|        TIFFHeaderUnion tif_header_swapped;
  588|    210|        if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    210|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (588:13): [True: 210, False: 0]
  ------------------
  589|    210|        {
  590|    210|            tif->tif_header.common.tiff_version = TIFF_VERSION_CLASSIC;
  ------------------
  |  |   48|    210|#define TIFF_VERSION_CLASSIC 42
  ------------------
  591|    210|            tif->tif_header.classic.tiff_diroff = 0;
  592|    210|            tif->tif_header_size = sizeof(TIFFHeaderClassic);
  593|       |            /* Swapped copy for writing */
  594|    210|            _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
  595|    210|                        sizeof(TIFFHeaderUnion));
  596|    210|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|    210|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (596:17): [True: 0, False: 210]
  ------------------
  597|      0|                TIFFSwabShort(&tif_header_swapped.common.tiff_version);
  598|    210|        }
  599|      0|        else
  600|      0|        {
  601|      0|            tif->tif_header.common.tiff_version = TIFF_VERSION_BIG;
  ------------------
  |  |   49|      0|#define TIFF_VERSION_BIG 43
  ------------------
  602|      0|            tif->tif_header.big.tiff_offsetsize = 8;
  603|      0|            tif->tif_header.big.tiff_unused = 0;
  604|      0|            tif->tif_header.big.tiff_diroff = 0;
  605|      0|            tif->tif_header_size = sizeof(TIFFHeaderBig);
  606|       |            /* Swapped copy for writing */
  607|      0|            _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
  608|      0|                        sizeof(TIFFHeaderUnion));
  609|      0|            if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (609:17): [True: 0, False: 0]
  ------------------
  610|      0|            {
  611|      0|                TIFFSwabShort(&tif_header_swapped.common.tiff_version);
  612|      0|                TIFFSwabShort(&tif_header_swapped.big.tiff_offsetsize);
  613|      0|            }
  614|      0|        }
  615|       |        /*
  616|       |         * The doc for "fopen" for some STD_C_LIBs says that if you
  617|       |         * open a file for modify ("+"), then you must fseek (or
  618|       |         * fflush?) between any freads and fwrites.  This is not
  619|       |         * necessary on most systems, but has been shown to be needed
  620|       |         * on Solaris.
  621|       |         */
  622|    210|        TIFFSeekFile(tif, 0, SEEK_SET);
  ------------------
  |  |  291|    210|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  623|    210|        if (!WriteOK(tif, &tif_header_swapped,
  ------------------
  |  |  311|    210|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|    210|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (623:13): [True: 0, False: 210]
  ------------------
  624|    210|                     (tmsize_t)(tif->tif_header_size)))
  625|      0|        {
  626|      0|            TIFFErrorExtR(tif, name, "Error writing TIFF header");
  627|      0|            goto bad;
  628|      0|        }
  629|       |        /*
  630|       |         * Setup default directory.
  631|       |         */
  632|    210|        if (!TIFFDefaultDirectory(tif))
  ------------------
  |  Branch (632:13): [True: 0, False: 210]
  ------------------
  633|      0|            goto bad;
  634|    210|        tif->tif_diroff = 0;
  635|    210|        tif->tif_lastdiroff = 0;
  636|    210|        tif->tif_setdirectory_force_absolute = FALSE;
  ------------------
  |  |   75|    210|#define FALSE 0
  ------------------
  637|       |        /* tif_curdircount = 0 means 'empty file opened for writing, but no IFD
  638|       |         * written yet' */
  639|    210|        tif->tif_curdircount = 0;
  640|    210|        return (tif);
  641|    210|    }
  642|       |
  643|       |    /*
  644|       |     * Setup the byte order handling according to the opened file for reading.
  645|       |     */
  646|      0|    if (tif->tif_header.common.tiff_magic != TIFF_BIGENDIAN &&
  ------------------
  |  |   51|      0|#define TIFF_BIGENDIAN 0x4d4d
  ------------------
  |  Branch (646:9): [True: 0, False: 0]
  ------------------
  647|      0|        tif->tif_header.common.tiff_magic != TIFF_LITTLEENDIAN
  ------------------
  |  |   52|      0|#define TIFF_LITTLEENDIAN 0x4949
  ------------------
  |  Branch (647:9): [True: 0, False: 0]
  ------------------
  648|      0|#if MDI_SUPPORT
  649|      0|        &&
  650|       |#if HOST_BIGENDIAN
  651|       |        tif->tif_header.common.tiff_magic != MDI_BIGENDIAN
  652|       |#else
  653|      0|        tif->tif_header.common.tiff_magic != MDI_LITTLEENDIAN
  ------------------
  |  |   53|      0|#define MDI_LITTLEENDIAN 0x5045
  ------------------
  |  Branch (653:9): [True: 0, False: 0]
  ------------------
  654|      0|#endif
  655|      0|    )
  656|      0|    {
  657|      0|        TIFFErrorExtR(tif, name,
  658|      0|                      "Not a TIFF or MDI file, bad magic number %" PRIu16
  659|      0|                      " (0x%" PRIx16 ")",
  660|       |#else
  661|       |    )
  662|       |    {
  663|       |        TIFFErrorExtR(tif, name,
  664|       |                      "Not a TIFF file, bad magic number %" PRIu16
  665|       |                      " (0x%" PRIx16 ")",
  666|       |#endif
  667|      0|                      tif->tif_header.common.tiff_magic,
  668|      0|                      tif->tif_header.common.tiff_magic);
  669|      0|        goto bad;
  670|      0|    }
  671|      0|    if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN)
  ------------------
  |  |   51|      0|#define TIFF_BIGENDIAN 0x4d4d
  ------------------
  |  Branch (671:9): [True: 0, False: 0]
  ------------------
  672|      0|    {
  673|      0|#if !WORDS_BIGENDIAN
  674|      0|        tif->tif_flags |= TIFF_SWAB;
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  675|      0|#endif
  676|      0|    }
  677|      0|    else
  678|      0|    {
  679|       |#if WORDS_BIGENDIAN
  680|       |        tif->tif_flags |= TIFF_SWAB;
  681|       |#endif
  682|      0|    }
  683|      0|    if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (683:9): [True: 0, False: 0]
  ------------------
  684|      0|        TIFFSwabShort(&tif->tif_header.common.tiff_version);
  685|      0|    if ((tif->tif_header.common.tiff_version != TIFF_VERSION_CLASSIC) &&
  ------------------
  |  |   48|      0|#define TIFF_VERSION_CLASSIC 42
  ------------------
  |  Branch (685:9): [True: 0, False: 0]
  ------------------
  686|      0|        (tif->tif_header.common.tiff_version != TIFF_VERSION_BIG))
  ------------------
  |  |   49|      0|#define TIFF_VERSION_BIG 43
  ------------------
  |  Branch (686:9): [True: 0, False: 0]
  ------------------
  687|      0|    {
  688|      0|        TIFFErrorExtR(tif, name,
  689|      0|                      "Not a TIFF file, bad version number %" PRIu16
  690|      0|                      " (0x%" PRIx16 ")",
  691|      0|                      tif->tif_header.common.tiff_version,
  692|      0|                      tif->tif_header.common.tiff_version);
  693|      0|        goto bad;
  694|      0|    }
  695|      0|    if (tif->tif_header.common.tiff_version == TIFF_VERSION_CLASSIC)
  ------------------
  |  |   48|      0|#define TIFF_VERSION_CLASSIC 42
  ------------------
  |  Branch (695:9): [True: 0, False: 0]
  ------------------
  696|      0|    {
  697|      0|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (697:13): [True: 0, False: 0]
  ------------------
  698|      0|            TIFFSwabLong(&tif->tif_header.classic.tiff_diroff);
  699|      0|        tif->tif_header_size = sizeof(TIFFHeaderClassic);
  700|      0|    }
  701|      0|    else
  702|      0|    {
  703|      0|        if (!ReadOK(tif,
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (703:13): [True: 0, False: 0]
  ------------------
  704|      0|                    ((uint8_t *)(&tif->tif_header) + sizeof(TIFFHeaderClassic)),
  705|      0|                    (sizeof(TIFFHeaderBig) - sizeof(TIFFHeaderClassic))))
  706|      0|        {
  707|      0|            TIFFErrorExtR(tif, name, "Cannot read TIFF header");
  708|      0|            goto bad;
  709|      0|        }
  710|      0|        if (tif->tif_flags & TIFF_SWAB)
  ------------------
  |  |  129|      0|#define TIFF_SWAB 0x00080U        /* byte swap file information */
  ------------------
  |  Branch (710:13): [True: 0, False: 0]
  ------------------
  711|      0|        {
  712|      0|            TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize);
  713|      0|            TIFFSwabLong8(&tif->tif_header.big.tiff_diroff);
  714|      0|        }
  715|      0|        if (tif->tif_header.big.tiff_offsetsize != 8)
  ------------------
  |  Branch (715:13): [True: 0, False: 0]
  ------------------
  716|      0|        {
  717|      0|            TIFFErrorExtR(tif, name,
  718|      0|                          "Not a TIFF file, bad BigTIFF offsetsize %" PRIu16
  719|      0|                          " (0x%" PRIx16 ")",
  720|      0|                          tif->tif_header.big.tiff_offsetsize,
  721|      0|                          tif->tif_header.big.tiff_offsetsize);
  722|      0|            goto bad;
  723|      0|        }
  724|      0|        if (tif->tif_header.big.tiff_unused != 0)
  ------------------
  |  Branch (724:13): [True: 0, False: 0]
  ------------------
  725|      0|        {
  726|      0|            TIFFErrorExtR(tif, name,
  727|      0|                          "Not a TIFF file, bad BigTIFF unused %" PRIu16
  728|      0|                          " (0x%" PRIx16 ")",
  729|      0|                          tif->tif_header.big.tiff_unused,
  730|      0|                          tif->tif_header.big.tiff_unused);
  731|      0|            goto bad;
  732|      0|        }
  733|      0|        tif->tif_header_size = sizeof(TIFFHeaderBig);
  734|      0|        tif->tif_flags |= TIFF_BIGTIFF;
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  735|      0|    }
  736|      0|    tif->tif_flags |= TIFF_MYBUFFER;
  ------------------
  |  |  131|      0|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  737|      0|    tif->tif_rawcp = tif->tif_rawdata = 0;
  738|      0|    tif->tif_rawdatasize = 0;
  739|      0|    tif->tif_rawdataoff = 0;
  740|      0|    tif->tif_rawdataloaded = 0;
  741|       |
  742|      0|    switch (mode[0])
  743|      0|    {
  744|      0|        case 'r':
  ------------------
  |  Branch (744:9): [True: 0, False: 0]
  ------------------
  745|      0|            if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (745:17): [True: 0, False: 0]
  ------------------
  746|      0|                tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff;
  747|      0|            else
  748|      0|                tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff;
  749|       |            /*
  750|       |             * Try to use a memory-mapped file if the client
  751|       |             * has not explicitly suppressed usage with the
  752|       |             * 'm' flag in the open mode (see above).
  753|       |             */
  754|      0|            if (tif->tif_flags & TIFF_MAPPED)
  ------------------
  |  |  133|      0|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  ------------------
  |  Branch (754:17): [True: 0, False: 0]
  ------------------
  755|      0|            {
  756|      0|                toff_t n;
  757|      0|                if (TIFFMapFileContents(tif, (void **)(&tif->tif_base), &n))
  ------------------
  |  |  295|      0|    ((*(tif)->tif_mapproc)((tif)->tif_clientdata, (paddr), (psize)))
  |  |  ------------------
  |  |  |  Branch (295:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  758|      0|                {
  759|      0|                    tif->tif_size = (tmsize_t)n;
  760|      0|                    assert((toff_t)tif->tif_size == n);
  ------------------
  |  Branch (760:21): [True: 0, False: 0]
  |  Branch (760:21): [True: 0, False: 0]
  ------------------
  761|      0|                }
  762|      0|                else
  763|      0|                    tif->tif_flags &= ~TIFF_MAPPED;
  ------------------
  |  |  133|      0|#define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
  ------------------
  764|      0|            }
  765|       |            /*
  766|       |             * Sometimes we do not want to read the first directory (for
  767|       |             * example, it may be broken) and want to proceed to other
  768|       |             * directories. I this case we use the TIFF_HEADERONLY flag to open
  769|       |             * file and return immediately after reading TIFF header.
  770|       |             * However, the pointer to TIFFSetField() and TIFFGetField()
  771|       |             * (i.e. tif->tif_tagmethods.vsetfield and
  772|       |             * tif->tif_tagmethods.vgetfield) need to be initialized, which is
  773|       |             * done in TIFFDefaultDirectory().
  774|       |             */
  775|      0|            if (tif->tif_flags & TIFF_HEADERONLY)
  ------------------
  |  |  139|      0|    0x10000U /* read header only, do not process the first directory */
  ------------------
  |  Branch (775:17): [True: 0, False: 0]
  ------------------
  776|      0|            {
  777|      0|                if (!TIFFDefaultDirectory(tif))
  ------------------
  |  Branch (777:21): [True: 0, False: 0]
  ------------------
  778|      0|                    goto bad;
  779|      0|                return (tif);
  780|      0|            }
  781|       |
  782|       |            /*
  783|       |             * Setup initial directory.
  784|       |             */
  785|      0|            if (TIFFReadDirectory(tif))
  ------------------
  |  Branch (785:17): [True: 0, False: 0]
  ------------------
  786|      0|            {
  787|      0|                return (tif);
  788|      0|            }
  789|      0|            break;
  790|      0|        case 'a':
  ------------------
  |  Branch (790:9): [True: 0, False: 0]
  ------------------
  791|       |            /*
  792|       |             * New directories are automatically append
  793|       |             * to the end of the directory chain when they
  794|       |             * are written out (see TIFFWriteDirectory).
  795|       |             */
  796|      0|            if (!TIFFDefaultDirectory(tif))
  ------------------
  |  Branch (796:17): [True: 0, False: 0]
  ------------------
  797|      0|                goto bad;
  798|      0|            return (tif);
  799|      0|        default:
  ------------------
  |  Branch (799:9): [True: 0, False: 0]
  ------------------
  800|      0|            break;
  801|      0|    }
  802|      0|bad:
  803|      0|    tif->tif_mode = O_RDONLY; /* XXX avoid flush */
  804|      0|    TIFFCleanup(tif);
  805|      0|bad2:
  806|      0|    return ((TIFF *)0);
  807|      0|}

TIFFInitPackBits:
  354|    175|{
  355|    175|    (void)scheme;
  356|    175|    tif->tif_decoderow = PackBitsDecode;
  357|    175|    tif->tif_decodestrip = PackBitsDecode;
  358|    175|    tif->tif_decodetile = PackBitsDecode;
  359|    175|#ifndef PACKBITS_READ_ONLY
  360|    175|    tif->tif_preencode = PackBitsPreEncode;
  361|    175|    tif->tif_postencode = PackBitsPostEncode;
  362|    175|    tif->tif_encoderow = PackBitsEncode;
  363|    175|    tif->tif_encodestrip = PackBitsEncodeChunk;
  364|    175|    tif->tif_encodetile = PackBitsEncodeChunk;
  365|    175|#endif
  366|    175|    tif->tif_getmaxcompressionratio = PackBitsGetMaxCompressionRatio;
  367|       |
  368|    175|    return (1);
  369|    175|}

_TIFFNoPostDecode:
 1869|    207|{
 1870|    207|    (void)tif;
 1871|    207|    (void)buf;
 1872|    207|    (void)cc;
 1873|    207|}

TIFFNumberOfStrips:
   77|    417|{
   78|    417|    TIFFDirectory *td = &tif->tif_dir;
   79|    417|    uint32_t nstrips;
   80|       |
   81|    417|    if (td->td_rowsperstrip == 0)
  ------------------
  |  Branch (81:9): [True: 0, False: 417]
  ------------------
   82|      0|    {
   83|      0|        TIFFWarningExtR(tif, "TIFFNumberOfStrips", "RowsPerStrip is zero");
   84|      0|        return 0;
   85|      0|    }
   86|    417|    nstrips = (td->td_rowsperstrip == (uint32_t)-1
  ------------------
  |  Branch (86:16): [True: 3, False: 414]
  ------------------
   87|    417|                   ? 1
   88|    417|                   : TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
  ------------------
  |  |  316|    414|    (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
  |  |  ------------------
  |  |  |  Branch (316:6): [True: 414, False: 0]
  |  |  ------------------
  |  |  317|    414|         ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
  |  |  318|    414|         : 0U)
  ------------------
   89|    417|    if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
  ------------------
  |  |  266|    417|#define PLANARCONFIG_SEPARATE 2            /* separate planes of data */
  ------------------
  |  Branch (89:9): [True: 0, False: 417]
  ------------------
   90|      0|        nstrips =
   91|      0|            _TIFFMultiply32(tif, nstrips, (uint32_t)td->td_samplesperpixel,
   92|      0|                            "TIFFNumberOfStrips");
   93|    417|    return (nstrips);
   94|    417|}
_TIFFStrileSize64:
  101|    794|{
  102|    794|    static const char module[] = "_TIFFStrileSize64";
  103|    794|    TIFFDirectory *td = &tif->tif_dir;
  104|    794|    if (isStrip)
  ------------------
  |  Branch (104:9): [True: 794, False: 0]
  ------------------
  105|    794|    {
  106|    794|        if (nrows == (uint32_t)(-1))
  ------------------
  |  Branch (106:13): [True: 0, False: 794]
  ------------------
  107|      0|            nrows = td->td_imagelength;
  108|    794|    }
  109|      0|    else
  110|      0|    {
  111|      0|        if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
  ------------------
  |  Branch (111:13): [True: 0, False: 0]
  |  Branch (111:39): [True: 0, False: 0]
  ------------------
  112|      0|            td->td_tiledepth == 0)
  ------------------
  |  Branch (112:13): [True: 0, False: 0]
  ------------------
  113|      0|            return (0);
  114|      0|    }
  115|    794|    if ((td->td_planarconfig == PLANARCONFIG_CONTIG) &&
  ------------------
  |  |  265|    794|#define PLANARCONFIG_CONTIG 1              /* single image plane */
  ------------------
  |  Branch (115:9): [True: 794, False: 0]
  ------------------
  116|    794|        (td->td_photometric == PHOTOMETRIC_YCBCR) && (!isUpSampled(tif)))
  ------------------
  |  |  227|    794|#define PHOTOMETRIC_YCBCR 6                /* !CCIR 601 */
  ------------------
                      (td->td_photometric == PHOTOMETRIC_YCBCR) && (!isUpSampled(tif)))
  ------------------
  |  |  285|      0|#define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
  |  |  ------------------
  |  |  |  |  136|      0|#define TIFF_UPSAMPLED 0x04000U   /* library is doing data up-sampling */
  |  |  ------------------
  ------------------
  |  Branch (116:9): [True: 0, False: 794]
  |  Branch (116:54): [True: 0, False: 0]
  ------------------
  117|      0|    {
  118|       |        /*
  119|       |         * Packed YCbCr data contain one Cb+Cr for every
  120|       |         * HorizontalSampling*VerticalSampling Y values.
  121|       |         * Must also roundup width and height when calculating
  122|       |         * since images that are not a multiple of the
  123|       |         * horizontal/vertical subsampling area include
  124|       |         * YCbCr data for the extended image.
  125|       |         */
  126|      0|        uint16_t ycbcrsubsampling[2];
  127|      0|        uint16_t samplingblock_samples;
  128|      0|        uint32_t samplingblocks_hor;
  129|      0|        uint32_t samplingblocks_ver;
  130|      0|        uint64_t samplingrow_samples;
  131|      0|        uint64_t samplingrow_size;
  132|      0|        if (td->td_samplesperpixel != 3)
  ------------------
  |  Branch (132:13): [True: 0, False: 0]
  ------------------
  133|      0|        {
  134|      0|            TIFFErrorExtR(tif, module, "Invalid td_samplesperpixel value");
  135|      0|            return 0;
  136|      0|        }
  137|      0|        TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING,
  ------------------
  |  |  388|      0|#define TIFFTAG_YCBCRSUBSAMPLING 530       /* !YCbCr subsampling factors */
  ------------------
  138|      0|                              ycbcrsubsampling + 0, ycbcrsubsampling + 1);
  139|      0|        if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 &&
  ------------------
  |  Branch (139:14): [True: 0, False: 0]
  |  Branch (139:42): [True: 0, False: 0]
  ------------------
  140|      0|             ycbcrsubsampling[0] != 4) ||
  ------------------
  |  Branch (140:14): [True: 0, False: 0]
  ------------------
  141|      0|            (ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 &&
  ------------------
  |  Branch (141:14): [True: 0, False: 0]
  |  Branch (141:42): [True: 0, False: 0]
  ------------------
  142|      0|             ycbcrsubsampling[1] != 4) ||
  ------------------
  |  Branch (142:14): [True: 0, False: 0]
  ------------------
  143|      0|            (ycbcrsubsampling[0] == 0 || ycbcrsubsampling[1] == 0))
  ------------------
  |  Branch (143:14): [True: 0, False: 0]
  |  Branch (143:42): [True: 0, False: 0]
  ------------------
  144|      0|        {
  145|      0|            TIFFErrorExtR(tif, module, "Invalid YCbCr subsampling (%dx%d)",
  146|      0|                          ycbcrsubsampling[0], ycbcrsubsampling[1]);
  147|      0|            return 0;
  148|      0|        }
  149|      0|        samplingblock_samples =
  150|      0|            (uint16_t)(ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2);
  151|      0|        const uint32_t width = isStrip ? td->td_imagewidth : td->td_tilewidth;
  ------------------
  |  Branch (151:32): [True: 0, False: 0]
  ------------------
  152|      0|        samplingblocks_hor = TIFFhowmany_32(width, ycbcrsubsampling[0]);
  ------------------
  |  |  316|      0|    (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
  |  |  ------------------
  |  |  |  Branch (316:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  317|      0|         ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
  |  |  318|      0|         : 0U)
  ------------------
  153|      0|        samplingblocks_ver = TIFFhowmany_32(nrows, ycbcrsubsampling[1]);
  ------------------
  |  |  316|      0|    (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
  |  |  ------------------
  |  |  |  Branch (316:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  317|      0|         ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
  |  |  318|      0|         : 0U)
  ------------------
  154|      0|        samplingrow_samples = _TIFFMultiply64(tif, samplingblocks_hor,
  155|      0|                                              samplingblock_samples, module);
  156|      0|        samplingrow_size = TIFFhowmany8_64(_TIFFMultiply64(
  ------------------
  |  |  330|      0|    (((x) & 0x07) ? ((uint64_t)(x) >> 3) + 1 : (uint64_t)(x) >> 3)
  |  |  ------------------
  |  |  |  Branch (330:6): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  157|      0|            tif, samplingrow_samples, td->td_bitspersample, module));
  158|      0|        return (
  159|      0|            _TIFFMultiply64(tif, samplingrow_size, samplingblocks_ver, module));
  160|      0|    }
  161|    794|    else
  162|    794|        return (_TIFFMultiply64(tif, nrows,
  163|    794|                                isStrip ? TIFFScanlineSize64(tif)
  ------------------
  |  Branch (163:33): [True: 794, False: 0]
  ------------------
  164|    794|                                        : TIFFTileRowSize64(tif),
  165|    794|                                module));
  166|    794|}
TIFFVStripSize64:
  172|    794|{
  173|    794|    return _TIFFStrileSize64(tif, nrows, /* isStrip = */ TRUE);
  ------------------
  |  |   74|    794|#define TRUE 1
  ------------------
  174|    794|}
TIFFStripSize64:
  231|    794|{
  232|    794|    TIFFDirectory *td = &tif->tif_dir;
  233|    794|    uint32_t rps = td->td_rowsperstrip;
  234|    794|    if (rps > td->td_imagelength)
  ------------------
  |  Branch (234:9): [True: 3, False: 791]
  ------------------
  235|      3|        rps = td->td_imagelength;
  236|    794|    return (TIFFVStripSize64(tif, rps));
  237|    794|}
TIFFStripSize:
  239|    417|{
  240|    417|    static const char module[] = "TIFFStripSize";
  241|    417|    uint64_t m;
  242|    417|    m = TIFFStripSize64(tif);
  243|    417|    return _TIFFCastUInt64ToSSize(tif, m, module);
  244|    417|}
TIFFScanlineSize64:
  292|  1.00k|{
  293|  1.00k|    static const char module[] = "TIFFScanlineSize64";
  294|  1.00k|    TIFFDirectory *td = &tif->tif_dir;
  295|  1.00k|    uint64_t scanline_size;
  296|  1.00k|    if (td->td_planarconfig == PLANARCONFIG_CONTIG)
  ------------------
  |  |  265|  1.00k|#define PLANARCONFIG_CONTIG 1              /* single image plane */
  ------------------
  |  Branch (296:9): [True: 1.00k, False: 0]
  ------------------
  297|  1.00k|    {
  298|  1.00k|        if ((td->td_photometric == PHOTOMETRIC_YCBCR) &&
  ------------------
  |  |  227|  1.00k|#define PHOTOMETRIC_YCBCR 6                /* !CCIR 601 */
  ------------------
  |  Branch (298:13): [True: 0, False: 1.00k]
  ------------------
  299|      0|            (td->td_samplesperpixel == 3) && (!isUpSampled(tif)))
  ------------------
  |  |  285|      0|#define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
  |  |  ------------------
  |  |  |  |  136|      0|#define TIFF_UPSAMPLED 0x04000U   /* library is doing data up-sampling */
  |  |  ------------------
  ------------------
  |  Branch (299:13): [True: 0, False: 0]
  |  Branch (299:46): [True: 0, False: 0]
  ------------------
  300|      0|        {
  301|      0|            uint16_t ycbcrsubsampling[2];
  302|      0|            uint16_t samplingblock_samples;
  303|      0|            uint32_t samplingblocks_hor;
  304|      0|            uint64_t samplingrow_samples;
  305|      0|            uint64_t samplingrow_size;
  306|      0|            if (td->td_samplesperpixel != 3)
  ------------------
  |  Branch (306:17): [True: 0, False: 0]
  ------------------
  307|      0|            {
  308|      0|                TIFFErrorExtR(tif, module, "Invalid td_samplesperpixel value");
  309|      0|                return 0;
  310|      0|            }
  311|      0|            TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING,
  ------------------
  |  |  388|      0|#define TIFFTAG_YCBCRSUBSAMPLING 530       /* !YCbCr subsampling factors */
  ------------------
  312|      0|                                  ycbcrsubsampling + 0, ycbcrsubsampling + 1);
  313|      0|            if (((ycbcrsubsampling[0] != 1) && (ycbcrsubsampling[0] != 2) &&
  ------------------
  |  Branch (313:18): [True: 0, False: 0]
  |  Branch (313:48): [True: 0, False: 0]
  ------------------
  314|      0|                 (ycbcrsubsampling[0] != 4)) ||
  ------------------
  |  Branch (314:18): [True: 0, False: 0]
  ------------------
  315|      0|                ((ycbcrsubsampling[1] != 1) && (ycbcrsubsampling[1] != 2) &&
  ------------------
  |  Branch (315:18): [True: 0, False: 0]
  |  Branch (315:48): [True: 0, False: 0]
  ------------------
  316|      0|                 (ycbcrsubsampling[1] != 4)) ||
  ------------------
  |  Branch (316:18): [True: 0, False: 0]
  ------------------
  317|      0|                ((ycbcrsubsampling[0] == 0) || (ycbcrsubsampling[1] == 0)))
  ------------------
  |  Branch (317:18): [True: 0, False: 0]
  |  Branch (317:48): [True: 0, False: 0]
  ------------------
  318|      0|            {
  319|      0|                TIFFErrorExtR(tif, module, "Invalid YCbCr subsampling");
  320|      0|                return 0;
  321|      0|            }
  322|      0|            samplingblock_samples =
  323|      0|                (uint16_t)(ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2);
  324|      0|            samplingblocks_hor =
  325|      0|                TIFFhowmany_32(td->td_imagewidth, ycbcrsubsampling[0]);
  ------------------
  |  |  316|      0|    (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
  |  |  ------------------
  |  |  |  Branch (316:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  317|      0|         ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
  |  |  318|      0|         : 0U)
  ------------------
  326|      0|            samplingrow_samples = _TIFFMultiply64(
  327|      0|                tif, samplingblocks_hor, samplingblock_samples, module);
  328|      0|            samplingrow_size =
  329|      0|                TIFFhowmany_64(_TIFFMultiply64(tif, samplingrow_samples,
  ------------------
  |  |  328|      0|    ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
  ------------------
  330|      0|                                               td->td_bitspersample, module),
  331|      0|                               8);
  332|      0|            scanline_size = (samplingrow_size / ycbcrsubsampling[1]);
  333|      0|        }
  334|  1.00k|        else
  335|  1.00k|        {
  336|  1.00k|            uint64_t scanline_samples;
  337|  1.00k|            uint32_t scanline_width = td->td_imagewidth;
  338|       |
  339|       |#if 0
  340|       |            // Tries to fix https://gitlab.com/libtiff/libtiff/-/merge_requests/564
  341|       |            // but causes regression when decoding legit files with tiffcp -c none
  342|       |            // Cf https://gitlab.com/libtiff/libtiff/-/merge_requests/644
  343|       |            if (td->td_photometric == PHOTOMETRIC_YCBCR)
  344|       |            {
  345|       |                uint16_t subsampling_hor;
  346|       |                uint16_t ignored;
  347|       |                TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING,
  348|       |                                      &subsampling_hor, &ignored);
  349|       |                if (subsampling_hor > 1) // roundup width for YCbCr
  350|       |                    scanline_width =
  351|       |                        TIFFroundup_32(scanline_width, subsampling_hor);
  352|       |            }
  353|       |#endif
  354|       |
  355|  1.00k|            scanline_samples = _TIFFMultiply64(tif, scanline_width,
  356|  1.00k|                                               td->td_samplesperpixel, module);
  357|  1.00k|            scanline_size =
  358|  1.00k|                TIFFhowmany_64(_TIFFMultiply64(tif, scanline_samples,
  ------------------
  |  |  328|  1.00k|    ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
  ------------------
  359|  1.00k|                                               td->td_bitspersample, module),
  360|  1.00k|                               8);
  361|  1.00k|        }
  362|  1.00k|    }
  363|      0|    else
  364|      0|    {
  365|      0|        scanline_size =
  366|      0|            TIFFhowmany_64(_TIFFMultiply64(tif, td->td_imagewidth,
  ------------------
  |  |  328|      0|    ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
  ------------------
  367|      0|                                           td->td_bitspersample, module),
  368|      0|                           8);
  369|      0|    }
  370|  1.00k|    if (scanline_size == 0)
  ------------------
  |  Branch (370:9): [True: 3, False: 998]
  ------------------
  371|      3|    {
  372|      3|        TIFFErrorExtR(tif, module, "Computed scanline size is zero");
  373|      3|        return 0;
  374|      3|    }
  375|    998|    return (scanline_size);
  376|  1.00k|}
TIFFScanlineSize:
  378|    207|{
  379|    207|    static const char module[] = "TIFFScanlineSize";
  380|    207|    uint64_t m;
  381|    207|    m = TIFFScanlineSize64(tif);
  382|    207|    return _TIFFCastUInt64ToSSize(tif, m, module);
  383|    207|}

TIFFFdOpenExt:
  217|    210|{
  218|    210|    TIFF *tif;
  219|       |
  220|    210|    fd_as_handle_union_t fdh;
  221|    210|    fdh.fd = fd;
  222|    210|    tif = TIFFClientOpenExt(name, mode, fdh.h, _tiffReadProc, _tiffWriteProc,
  223|    210|                            _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
  224|    210|                            _tiffMapProc, _tiffUnmapProc, opts);
  225|    210|    if (tif)
  ------------------
  |  Branch (225:9): [True: 210, False: 0]
  ------------------
  226|    210|        tif->tif_fd = fd;
  227|    210|    return (tif);
  228|    210|}
TIFFOpen:
  234|    210|{
  235|       |    return TIFFOpenExt(name, mode, NULL);
  236|    210|}
TIFFOpenExt:
  239|    210|{
  240|    210|    static const char module[] = "TIFFOpen";
  241|    210|    int m, fd;
  242|    210|    TIFF *tif;
  243|       |
  244|    210|    m = _TIFFgetMode(opts, NULL, mode, module);
  245|    210|    if (m == -1)
  ------------------
  |  Branch (245:9): [True: 0, False: 210]
  ------------------
  246|      0|        return ((TIFF *)0);
  247|       |
  248|       |/* for cygwin and mingw */
  249|       |#ifdef O_BINARY
  250|       |    m |= O_BINARY;
  251|       |#endif
  252|       |
  253|    210|    fd = open(name, m, 0666);
  254|    210|    if (fd < 0)
  ------------------
  |  Branch (254:9): [True: 0, False: 210]
  ------------------
  255|      0|    {
  256|      0|        if (errno > 0 && strerror(errno) != NULL)
  ------------------
  |  Branch (256:13): [True: 0, False: 0]
  |  Branch (256:26): [True: 0, False: 0]
  ------------------
  257|      0|        {
  258|      0|            _TIFFErrorEarly(opts, NULL, module, "%s: %s", name,
  259|      0|                            strerror(errno));
  260|      0|        }
  261|      0|        else
  262|      0|        {
  263|      0|            _TIFFErrorEarly(opts, NULL, module, "%s: Cannot open", name);
  264|      0|        }
  265|      0|        return ((TIFF *)0);
  266|      0|    }
  267|       |
  268|    210|    tif = TIFFFdOpenExt((int)fd, name, mode, opts);
  269|    210|    if (!tif)
  ------------------
  |  Branch (269:9): [True: 0, False: 210]
  ------------------
  270|      0|        close(fd);
  271|    210|    return tif;
  272|    210|}
_TIFFmalloc:
  335|  1.43k|{
  336|  1.43k|    if (s == 0)
  ------------------
  |  Branch (336:9): [True: 0, False: 1.43k]
  ------------------
  337|      0|        return ((void *)NULL);
  338|       |
  339|  1.43k|    return (malloc((size_t)s));
  340|  1.43k|}
_TIFFcalloc:
  343|    340|{
  344|    340|    if (nmemb == 0 || siz == 0)
  ------------------
  |  Branch (344:9): [True: 0, False: 340]
  |  Branch (344:23): [True: 0, False: 340]
  ------------------
  345|      0|        return ((void *)NULL);
  346|       |
  347|    340|    return calloc((size_t)nmemb, (size_t)siz);
  348|    340|}
_TIFFfree:
  350|  3.62k|void _TIFFfree(void *p) { free(p); }
_TIFFrealloc:
  352|  1.85k|void *_TIFFrealloc(void *p, tmsize_t s) { return (realloc(p, (size_t)s)); }
_TIFFmemset:
  354|  2.86k|void _TIFFmemset(void *p, int v, tmsize_t c) { memset(p, v, (size_t)c); }
_TIFFmemcpy:
  357|  5.61k|{
  358|  5.61k|    memcpy(d, s, (size_t)c);
  359|  5.61k|}
tif_unix.c:_tiffWriteProc:
  100|  1.09k|{
  101|  1.09k|    fd_as_handle_union_t fdh;
  102|  1.09k|    const size_t bytes_total = (size_t)size;
  103|  1.09k|    size_t bytes_written;
  104|  1.09k|    tmsize_t count = -1;
  105|  1.09k|    if ((tmsize_t)bytes_total != size)
  ------------------
  |  Branch (105:9): [True: 0, False: 1.09k]
  ------------------
  106|      0|    {
  107|      0|        errno = EINVAL;
  108|      0|        return (tmsize_t)-1;
  109|      0|    }
  110|  1.09k|    fdh.h = fd;
  111|  2.19k|    for (bytes_written = 0; bytes_written < bytes_total;
  ------------------
  |  Branch (111:29): [True: 1.09k, False: 1.09k]
  ------------------
  112|  1.09k|         bytes_written += (size_t)count)
  113|  1.09k|    {
  114|  1.09k|        const char *buf_offset = (char *)buf + bytes_written;
  115|  1.09k|        size_t io_size = (size_t)(bytes_total - bytes_written);
  116|  1.09k|        if (io_size > TIFF_IO_MAX)
  ------------------
  |  |   60|  1.09k|#define TIFF_IO_MAX 2147483647U
  ------------------
  |  Branch (116:13): [True: 0, False: 1.09k]
  ------------------
  117|      0|            io_size = TIFF_IO_MAX;
  ------------------
  |  |   60|      0|#define TIFF_IO_MAX 2147483647U
  ------------------
  118|       |        /* Below is an obvious false positive of Coverity Scan */
  119|       |        /* coverity[overflow_sink] */
  120|  1.09k|        count = write(fdh.fd, buf_offset, (TIFFIOSize_t)io_size);
  121|  1.09k|        if (count <= 0)
  ------------------
  |  Branch (121:13): [True: 0, False: 1.09k]
  ------------------
  122|      0|            break;
  123|  1.09k|    }
  124|  1.09k|    if (count < 0)
  ------------------
  |  Branch (124:9): [True: 0, False: 1.09k]
  ------------------
  125|      0|        return (tmsize_t)-1;
  126|       |    /* Silence Coverity Scan warning about unsigned to signed underflow. */
  127|       |    /* coverity[return_overflow:SUPPRESS] */
  128|  1.09k|    return (tmsize_t)bytes_written;
  129|       |    /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */
  130|  1.09k|}
tif_unix.c:_tiffSeekProc:
  133|  1.26k|{
  134|  1.26k|    fd_as_handle_union_t fdh;
  135|  1.26k|    _TIFF_off_t off_io = (_TIFF_off_t)off;
  ------------------
  |  |  407|  1.26k|#define _TIFF_off_t off_t
  ------------------
  136|  1.26k|    if ((uint64_t)off_io != off)
  ------------------
  |  Branch (136:9): [True: 0, False: 1.26k]
  ------------------
  137|      0|    {
  138|      0|        errno = EINVAL;
  139|      0|        return (uint64_t)-1; /* this is really gross */
  140|      0|    }
  141|  1.26k|    fdh.h = fd;
  142|  1.26k|    return ((uint64_t)_TIFF_lseek_f(fdh.fd, off_io, whence));
  ------------------
  |  |  400|  1.26k|#define _TIFF_lseek_f(fildes, offset, whence) lseek(fildes, offset, whence)
  ------------------
  143|  1.26k|}
tif_unix.c:_tiffCloseProc:
  146|    210|{
  147|    210|    fd_as_handle_union_t fdh;
  148|    210|    fdh.h = fd;
  149|    210|    return (close(fdh.fd));
  150|    210|}
tif_unix.c:unixErrorHandler:
  379|     43|{
  380|     43|    if (module != NULL)
  ------------------
  |  Branch (380:9): [True: 43, False: 0]
  ------------------
  381|     43|        fprintf(stderr, "%s: ", module);
  382|     43|    vfprintf(stderr, fmt, ap);
  383|       |    fprintf(stderr, ".\n");
  384|     43|}

TIFFWriteEncodedStrip:
  260|    210|{
  261|    210|    static const char module[] = "TIFFWriteEncodedStrip";
  262|    210|    TIFFDirectory *td = &tif->tif_dir;
  263|    210|    uint16_t sample;
  264|       |
  265|    210|    if (!WRITECHECKSTRIPS(tif, module))
  ------------------
  |  |   38|    210|    (((tif)->tif_flags & TIFF_BEENWRITING) || TIFFWriteCheck((tif), 0, module))
  |  |  ------------------
  |  |  |  |  128|    210|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  |  |  ------------------
  |  |  |  Branch (38:6): [True: 0, False: 210]
  |  |  |  Branch (38:47): [True: 207, False: 3]
  |  |  ------------------
  ------------------
  266|      3|        return ((tmsize_t)-1);
  267|       |    /*
  268|       |     * Check strip array to make sure there's space.
  269|       |     * We don't support dynamically growing files that
  270|       |     * have data organized in separate bitplanes because
  271|       |     * it's too painful.  In that case we require that
  272|       |     * the imagelength be set properly before the first
  273|       |     * write (so that the strips array will be fully
  274|       |     * allocated above).
  275|       |     */
  276|    207|    if (strip >= td->td_nstrips)
  ------------------
  |  Branch (276:9): [True: 0, False: 207]
  ------------------
  277|      0|    {
  278|      0|        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
  ------------------
  |  |  266|      0|#define PLANARCONFIG_SEPARATE 2            /* separate planes of data */
  ------------------
  |  Branch (278:13): [True: 0, False: 0]
  ------------------
  279|      0|        {
  280|      0|            TIFFErrorExtR(
  281|      0|                tif, module,
  282|      0|                "Can not grow image by strips when using separate planes");
  283|      0|            return ((tmsize_t)-1);
  284|      0|        }
  285|       |        /* TIFFGrowStrips() below extends the strip arrays by exactly one
  286|       |         * entry, so only the index immediately past the end can be served. */
  287|      0|        if (strip > td->td_nstrips)
  ------------------
  |  Branch (287:13): [True: 0, False: 0]
  ------------------
  288|      0|        {
  289|      0|            TIFFErrorExtR(tif, module, "%lu: Strip out of range, max %lu",
  290|      0|                          (unsigned long)strip, (unsigned long)td->td_nstrips);
  291|      0|            return ((tmsize_t)-1);
  292|      0|        }
  293|      0|        if (!TIFFGrowStrips(tif, 1, module))
  ------------------
  |  Branch (293:13): [True: 0, False: 0]
  ------------------
  294|      0|            return ((tmsize_t)-1);
  295|      0|        td->td_stripsperimage =
  296|      0|            TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);
  ------------------
  |  |  316|      0|    (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
  |  |  ------------------
  |  |  |  Branch (316:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  317|      0|         ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
  |  |  318|      0|         : 0U)
  ------------------
  297|      0|    }
  298|       |    /*
  299|       |     * Handle delayed allocation of data buffer.  This
  300|       |     * permits it to be sized according to the directory
  301|       |     * info.
  302|       |     */
  303|    207|    if (!BUFFERCHECK(tif))
  ------------------
  |  |   42|    207|    ((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) ||            \
  |  |  ------------------
  |  |  |  |  126|    207|#define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */
  |  |  ------------------
  |  |  |  Branch (42:7): [True: 0, False: 207]
  |  |  |  Branch (42:48): [True: 0, False: 0]
  |  |  ------------------
  |  |   43|    207|     TIFFWriteBufferSetup((tif), NULL, (tmsize_t)(-1)))
  |  |  ------------------
  |  |  |  Branch (43:6): [True: 207, False: 0]
  |  |  ------------------
  ------------------
  304|      0|        return ((tmsize_t)-1);
  305|       |
  306|    207|    tif->tif_flags |= TIFF_BUF4WRITE;
  ------------------
  |  |  144|    207|#define TIFF_BUF4WRITE 0x100000U  /* rawcc bytes are for writing */
  ------------------
  307|       |
  308|    207|    tif->tif_dir.td_curstrip = strip;
  309|       |
  310|       |    /* this informs TIFFAppendToStrip() we have changed or reset strip */
  311|    207|    tif->tif_curoff = 0;
  312|       |
  313|    207|    if (!_TIFFReserveLargeEnoughWriteBuffer(tif, strip))
  ------------------
  |  Branch (313:9): [True: 0, False: 207]
  ------------------
  314|      0|    {
  315|      0|        return ((tmsize_t)(-1));
  316|      0|    }
  317|       |
  318|    207|    tif->tif_rawcc = 0;
  319|    207|    tif->tif_rawcp = tif->tif_rawdata;
  320|       |
  321|    207|    if (td->td_stripsperimage == 0)
  ------------------
  |  Branch (321:9): [True: 0, False: 207]
  ------------------
  322|      0|    {
  323|      0|        TIFFErrorExtR(tif, module, "Zero strips per image");
  324|      0|        return ((tmsize_t)-1);
  325|      0|    }
  326|       |
  327|    207|    if (TIFFSafeModMul32(tif, module, strip, td->td_stripsperimage,
  ------------------
  |  |  346|    207|    ((dimension) == 0 || ((index) % (count) == 0)                              \
  |  |  ------------------
  |  |  |  Branch (346:5): [True: 0, False: 207]
  |  |  |  Branch (346:6): [True: 0, False: 207]
  |  |  |  Branch (346:26): [True: 207, False: 0]
  |  |  ------------------
  |  |  347|    207|         ? ((result) = 0, 0)                                                   \
  |  |  348|    207|         : (((result) = _TIFFMultiply32((tif), (index) % (count), (dimension), \
  |  |  349|      0|                                        (module))) == 0))
  ------------------
  328|    207|                         td->td_rowsperstrip, tif->tif_dir.td_row))
  329|      0|        return ((tmsize_t)-1);
  330|    207|    if ((tif->tif_flags & TIFF_CODERSETUP) == 0)
  ------------------
  |  |  127|    207|#define TIFF_CODERSETUP 0x00020U  /* encoder/decoder setup done */
  ------------------
  |  Branch (330:9): [True: 207, False: 0]
  ------------------
  331|    207|    {
  332|    207|        if (!(*tif->tif_setupencode)(tif))
  ------------------
  |  Branch (332:13): [True: 0, False: 207]
  ------------------
  333|      0|            return ((tmsize_t)-1);
  334|    207|        tif->tif_flags |= TIFF_CODERSETUP;
  ------------------
  |  |  127|    207|#define TIFF_CODERSETUP 0x00020U  /* encoder/decoder setup done */
  ------------------
  335|    207|    }
  336|       |
  337|    207|    tif->tif_flags &= ~TIFF_POSTENCODE;
  ------------------
  |  |  134|    207|#define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
  ------------------
  338|       |
  339|       |    /* shortcut to avoid an extra memcpy() */
  340|    207|    if (td->td_compression == COMPRESSION_NONE)
  ------------------
  |  |  182|    207|#define COMPRESSION_NONE 1            /* dump mode */
  ------------------
  |  Branch (340:9): [True: 207, False: 0]
  ------------------
  341|    207|    {
  342|       |        /* swab if needed - note that source buffer will be altered */
  343|    207|        tif->tif_postdecode(tif, (uint8_t *)data, cc);
  344|       |
  345|    207|        if (!isFillOrder(tif, td->td_fillorder) &&
  ------------------
  |  |  284|    414|#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  ------------------
  |  Branch (345:13): [True: 0, False: 207]
  ------------------
  346|      0|            (tif->tif_flags & TIFF_NOBITREV) == 0)
  ------------------
  |  |  130|      0|#define TIFF_NOBITREV 0x00100U    /* inhibit bit reversal logic */
  ------------------
  |  Branch (346:13): [True: 0, False: 0]
  ------------------
  347|      0|            TIFFReverseBits((uint8_t *)data, cc);
  348|       |
  349|    207|        if (cc > 0 && !TIFFAppendToStrip(tif, strip, (uint8_t *)data, cc))
  ------------------
  |  Branch (349:13): [True: 207, False: 0]
  |  Branch (349:23): [True: 0, False: 207]
  ------------------
  350|      0|            return ((tmsize_t)-1);
  351|    207|        return (cc);
  352|    207|    }
  353|       |
  354|      0|    sample = (uint16_t)(strip / td->td_stripsperimage);
  355|      0|    if (!(*tif->tif_preencode)(tif, sample))
  ------------------
  |  Branch (355:9): [True: 0, False: 0]
  ------------------
  356|      0|        return ((tmsize_t)-1);
  357|       |
  358|       |    /* swab if needed - note that source buffer will be altered */
  359|      0|    tif->tif_postdecode(tif, (uint8_t *)data, cc);
  360|       |
  361|      0|    if (!(*tif->tif_encodestrip)(tif, (uint8_t *)data, cc, sample))
  ------------------
  |  Branch (361:9): [True: 0, False: 0]
  ------------------
  362|      0|        return ((tmsize_t)-1);
  363|      0|    if (!(*tif->tif_postencode)(tif))
  ------------------
  |  Branch (363:9): [True: 0, False: 0]
  ------------------
  364|      0|        return ((tmsize_t)-1);
  365|      0|    if (!isFillOrder(tif, td->td_fillorder) &&
  ------------------
  |  |  284|      0|#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  ------------------
  |  Branch (365:9): [True: 0, False: 0]
  ------------------
  366|      0|        (tif->tif_flags & TIFF_NOBITREV) == 0)
  ------------------
  |  |  130|      0|#define TIFF_NOBITREV 0x00100U    /* inhibit bit reversal logic */
  ------------------
  |  Branch (366:9): [True: 0, False: 0]
  ------------------
  367|      0|        TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
  368|      0|    if (tif->tif_rawcc > 0 &&
  ------------------
  |  Branch (368:9): [True: 0, False: 0]
  ------------------
  369|      0|        !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
  ------------------
  |  Branch (369:9): [True: 0, False: 0]
  ------------------
  370|      0|        return ((tmsize_t)-1);
  371|      0|    tif->tif_rawcc = 0;
  372|      0|    tif->tif_rawcp = tif->tif_rawdata;
  373|      0|    return (cc);
  374|      0|}
TIFFSetupStrips:
  637|    207|{
  638|    207|    TIFFDirectory *td = &tif->tif_dir;
  639|       |
  640|    207|    if (isTiled(tif))
  ------------------
  |  |  282|    207|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    207|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  |  |  |  Branch (282:22): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  641|      0|        td->td_stripsperimage = isUnspecified(tif, FIELD_TILEDIMENSIONS)
  ------------------
  |  |  634|      0|    (TIFFFieldSet(tif, f) && (tif)->tif_dir.td_imagelength == 0)
  |  |  ------------------
  |  |  |  |  267|      0|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  |  |  ------------------
  |  |  |  |  |  |  266|      0|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  |  |  ------------------
  |  |  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  |  |  ------------------
  |  |  |  |  |  |  265|      0|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (267:34): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (634:30): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  642|      0|                                    ? td->td_samplesperpixel
  643|      0|                                    : TIFFNumberOfTiles(tif);
  644|    207|    else
  645|    207|        td->td_stripsperimage = isUnspecified(tif, FIELD_ROWSPERSTRIP)
  ------------------
  |  |  634|    207|    (TIFFFieldSet(tif, f) && (tif)->tif_dir.td_imagelength == 0)
  |  |  ------------------
  |  |  |  |  267|    414|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  |  |  ------------------
  |  |  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  |  |  ------------------
  |  |  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  |  |  ------------------
  |  |  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (267:34): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (634:30): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  646|    207|                                    ? td->td_samplesperpixel
  647|    207|                                    : TIFFNumberOfStrips(tif);
  648|    207|    td->td_nstrips = td->td_stripsperimage;
  649|       |    /* TIFFWriteDirectoryTagData has a limitation to 0x80000000U bytes */
  650|    207|    if (td->td_nstrips >=
  ------------------
  |  Branch (650:9): [True: 0, False: 207]
  ------------------
  651|    207|        0x80000000U / ((tif->tif_flags & TIFF_BIGTIFF) ? 0x8U : 0x4U))
  ------------------
  |  |  143|    207|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (651:24): [True: 0, False: 207]
  ------------------
  652|      0|    {
  653|      0|        TIFFErrorExtR(tif, "TIFFSetupStrips",
  654|      0|                      "Too large Strip/Tile Offsets/ByteCounts arrays");
  655|      0|        return 0;
  656|      0|    }
  657|    207|    if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
  ------------------
  |  |  266|    207|#define PLANARCONFIG_SEPARATE 2            /* separate planes of data */
  ------------------
  |  Branch (657:9): [True: 0, False: 207]
  ------------------
  658|      0|        td->td_stripsperimage /= td->td_samplesperpixel;
  659|       |
  660|    207|    if (td->td_stripoffset_p != NULL)
  ------------------
  |  Branch (660:9): [True: 0, False: 207]
  ------------------
  661|      0|        _TIFFfreeExt(tif, td->td_stripoffset_p);
  662|    207|    td->td_stripoffset_p = (uint64_t *)_TIFFCheckMalloc(
  663|    207|        tif, td->td_nstrips, sizeof(uint64_t), "for \"StripOffsets\" array");
  664|    207|    if (td->td_stripbytecount_p != NULL)
  ------------------
  |  Branch (664:9): [True: 0, False: 207]
  ------------------
  665|      0|        _TIFFfreeExt(tif, td->td_stripbytecount_p);
  666|    207|    td->td_stripbytecount_p = (uint64_t *)_TIFFCheckMalloc(
  667|    207|        tif, td->td_nstrips, sizeof(uint64_t), "for \"StripByteCounts\" array");
  668|    207|    if (td->td_stripoffset_p == NULL || td->td_stripbytecount_p == NULL)
  ------------------
  |  Branch (668:9): [True: 0, False: 207]
  |  Branch (668:41): [True: 0, False: 207]
  ------------------
  669|      0|        return (0);
  670|       |    /*
  671|       |     * Place data at the end-of-file
  672|       |     * (by setting offsets to zero).
  673|       |     */
  674|    207|    _TIFFmemset(td->td_stripoffset_p, 0,
  675|    207|                (tmsize_t)((size_t)td->td_nstrips * sizeof(uint64_t)));
  676|    207|    _TIFFmemset(td->td_stripbytecount_p, 0,
  677|    207|                (tmsize_t)((size_t)td->td_nstrips * sizeof(uint64_t)));
  678|    207|    TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
  ------------------
  |  |  268|    207|#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  679|    207|    TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
  ------------------
  |  |  268|    207|#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  266|    207|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
  |  |  ------------------
  |  |  |  |  265|    207|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  680|    207|    return (1);
  681|    207|}
TIFFWriteCheck:
  691|    210|{
  692|    210|    if (tif->tif_mode == O_RDONLY)
  ------------------
  |  Branch (692:9): [True: 0, False: 210]
  ------------------
  693|      0|    {
  694|      0|        TIFFErrorExtR(tif, module, "File not open for writing");
  695|      0|        return (0);
  696|      0|    }
  697|    210|    if (tiles ^ isTiled(tif))
  ------------------
  |  |  282|    210|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    210|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  ------------------
  |  Branch (697:9): [True: 0, False: 210]
  ------------------
  698|      0|    {
  699|      0|        TIFFErrorExtR(tif, module,
  700|      0|                      tiles ? "Can not write tiles to a striped image"
  ------------------
  |  Branch (700:23): [True: 0, False: 0]
  ------------------
  701|      0|                            : "Can not write scanlines to a tiled image");
  702|      0|        return (0);
  703|      0|    }
  704|       |
  705|    210|    _TIFFFillStriles(tif);
  706|       |
  707|       |    /*
  708|       |     * On the first write verify all the required information
  709|       |     * has been setup and initialize any data structures that
  710|       |     * had to wait until directory information was set.
  711|       |     * Note that a lot of our work is assumed to remain valid
  712|       |     * because we disallow any of the important parameters
  713|       |     * from changing after we start writing (i.e. once
  714|       |     * TIFF_BEENWRITING is set, TIFFSetField will only allow
  715|       |     * the image's length to be changed).
  716|       |     */
  717|    210|    if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS))
  ------------------
  |  |  267|    210|#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  266|    210|#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
  |  |  ------------------
  |  |               #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
  |  |  ------------------
  |  |  |  |  265|    210|#define BITn(n) (1U << ((n) & 0x1f))
  |  |  ------------------
  ------------------
  |  Branch (717:9): [True: 3, False: 207]
  ------------------
  718|      3|    {
  719|      3|        TIFFErrorExtR(tif, module,
  720|      3|                      "Must set \"ImageWidth\" before writing data");
  721|      3|        return (0);
  722|      3|    }
  723|    207|    if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))
  ------------------
  |  Branch (723:9): [True: 207, False: 0]
  |  Branch (723:50): [True: 0, False: 207]
  ------------------
  724|      0|    {
  725|      0|        tif->tif_dir.td_nstrips = 0;
  726|      0|        TIFFErrorExtR(tif, module, "No space for %s arrays",
  727|      0|                      isTiled(tif) ? "tile" : "strip");
  ------------------
  |  |  282|      0|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|      0|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  |  |  |  Branch (282:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  728|      0|        return (0);
  729|      0|    }
  730|    207|    if (isTiled(tif))
  ------------------
  |  |  282|    207|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    207|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  |  |  |  Branch (282:22): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  731|      0|    {
  732|      0|        tif->tif_dir.td_tilesize = TIFFTileSize(tif);
  733|      0|        if (tif->tif_dir.td_tilesize == 0)
  ------------------
  |  Branch (733:13): [True: 0, False: 0]
  ------------------
  734|      0|            return (0);
  735|      0|    }
  736|    207|    else
  737|    207|        tif->tif_dir.td_tilesize = (tmsize_t)(-1);
  738|    207|    tif->tif_dir.td_scanlinesize = TIFFScanlineSize(tif);
  739|    207|    if (tif->tif_dir.td_scanlinesize == 0)
  ------------------
  |  Branch (739:9): [True: 0, False: 207]
  ------------------
  740|      0|        return (0);
  741|    207|    tif->tif_flags |= TIFF_BEENWRITING;
  ------------------
  |  |  128|    207|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
  742|       |
  743|    207|    if (tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
  ------------------
  |  Branch (743:9): [True: 0, False: 207]
  ------------------
  744|      0|        tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&
  ------------------
  |  Branch (744:9): [True: 0, False: 0]
  ------------------
  745|      0|        tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&
  ------------------
  |  Branch (745:9): [True: 0, False: 0]
  ------------------
  746|      0|        tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 &&
  ------------------
  |  Branch (746:9): [True: 0, False: 0]
  ------------------
  747|      0|        tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 &&
  ------------------
  |  Branch (747:9): [True: 0, False: 0]
  ------------------
  748|      0|        tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&
  ------------------
  |  Branch (748:9): [True: 0, False: 0]
  ------------------
  749|      0|        tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&
  ------------------
  |  Branch (749:9): [True: 0, False: 0]
  ------------------
  750|      0|        tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 &&
  ------------------
  |  Branch (750:9): [True: 0, False: 0]
  ------------------
  751|      0|        !(tif->tif_flags & TIFF_DIRTYDIRECT))
  ------------------
  |  |  125|      0|#define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  ------------------
  |  Branch (751:9): [True: 0, False: 0]
  ------------------
  752|      0|    {
  753|      0|        if (!TIFFForceStrileArrayWriting(tif))
  ------------------
  |  Branch (753:13): [True: 0, False: 0]
  ------------------
  754|      0|        {
  755|       |            /* Write macros skip TIFFWriteCheck() while this flag is set */
  756|      0|            tif->tif_flags &= ~TIFF_BEENWRITING;
  ------------------
  |  |  128|      0|#define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  ------------------
  757|      0|            return (0);
  758|      0|        }
  759|      0|    }
  760|       |
  761|    207|    return (1);
  762|    207|}
TIFFWriteBufferSetup:
  768|    207|{
  769|    207|    static const char module[] = "TIFFWriteBufferSetup";
  770|       |
  771|       |    /* Size -1 selects the library default; any other size must be positive. */
  772|    207|    if (size != (tmsize_t)(-1) && size <= 0)
  ------------------
  |  Branch (772:9): [True: 0, False: 207]
  |  Branch (772:35): [True: 0, False: 0]
  ------------------
  773|      0|    {
  774|      0|        TIFFErrorExtR(tif, module,
  775|      0|                      "Invalid raw data buffer size %" TIFF_SSIZE_FORMAT, size);
  ------------------
  |  |  142|      0|#  define TIFF_SSIZE_FORMAT PRId64
  ------------------
  776|      0|        return (0);
  777|      0|    }
  778|       |
  779|    207|    if (tif->tif_rawdata)
  ------------------
  |  Branch (779:9): [True: 0, False: 207]
  ------------------
  780|      0|    {
  781|      0|        if (tif->tif_flags & TIFF_MYBUFFER)
  ------------------
  |  |  131|      0|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  |  Branch (781:13): [True: 0, False: 0]
  ------------------
  782|      0|        {
  783|      0|            _TIFFfreeExt(tif, tif->tif_rawdata);
  784|      0|            tif->tif_flags &= ~TIFF_MYBUFFER;
  ------------------
  |  |  131|      0|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  785|      0|        }
  786|      0|        tif->tif_rawdata = NULL;
  787|      0|        tif->tif_rawdatasize = 0;
  788|      0|    }
  789|    207|    if (size == (tmsize_t)(-1))
  ------------------
  |  Branch (789:9): [True: 207, False: 0]
  ------------------
  790|    207|    {
  791|    207|        size = (isTiled(tif) ? tif->tif_dir.td_tilesize : TIFFStripSize(tif));
  ------------------
  |  |  282|    207|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|    207|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  |  |  |  Branch (282:22): [True: 0, False: 207]
  |  |  ------------------
  ------------------
  792|       |
  793|       |        /* Adds 10% margin for cases where compression would expand a bit */
  794|    207|        if (size < TIFF_TMSIZE_T_MAX - size / 10)
  ------------------
  |  |   68|    207|#define TIFF_TMSIZE_T_MAX (tmsize_t)(SIZE_MAX >> 1)
  ------------------
  |  Branch (794:13): [True: 207, False: 0]
  ------------------
  795|    207|            size += size / 10;
  796|       |        /*
  797|       |         * Make raw data buffer at least 8K
  798|       |         */
  799|    207|        if (size < 8 * 1024)
  ------------------
  |  Branch (799:13): [True: 207, False: 0]
  ------------------
  800|    207|            size = 8 * 1024;
  801|    207|        bp = NULL; /* NB: force malloc */
  802|    207|    }
  803|    207|    if (bp == NULL)
  ------------------
  |  Branch (803:9): [True: 207, False: 0]
  ------------------
  804|    207|    {
  805|    207|        bp = _TIFFmallocExt(tif, size);
  806|    207|        if (bp == NULL)
  ------------------
  |  Branch (806:13): [True: 0, False: 207]
  ------------------
  807|      0|        {
  808|      0|            TIFFErrorExtR(tif, module, "No space for output buffer");
  809|      0|            return (0);
  810|      0|        }
  811|    207|        tif->tif_flags |= TIFF_MYBUFFER;
  ------------------
  |  |  131|    207|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  812|    207|    }
  813|      0|    else
  814|      0|        tif->tif_flags &= ~TIFF_MYBUFFER;
  ------------------
  |  |  131|      0|#define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
  ------------------
  815|    207|    tif->tif_rawdata = (uint8_t *)bp;
  816|    207|    tif->tif_rawdatasize = size;
  817|    207|    tif->tif_rawcc = 0;
  818|    207|    tif->tif_rawcp = tif->tif_rawdata;
  819|    207|    tif->tif_flags |= TIFF_BUFFERSETUP;
  ------------------
  |  |  126|    207|#define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */
  ------------------
  820|    207|    return (1);
  821|    207|}
TIFFFlushData1:
 1061|    207|{
 1062|    207|    if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE)
  ------------------
  |  |  144|      0|#define TIFF_BUF4WRITE 0x100000U  /* rawcc bytes are for writing */
  ------------------
  |  Branch (1062:9): [True: 0, False: 207]
  |  Branch (1062:31): [True: 0, False: 0]
  ------------------
 1063|      0|    {
 1064|      0|        if (!isFillOrder(tif, tif->tif_dir.td_fillorder) &&
  ------------------
  |  |  284|      0|#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  ------------------
  |  Branch (1064:13): [True: 0, False: 0]
  ------------------
 1065|      0|            (tif->tif_flags & TIFF_NOBITREV) == 0)
  ------------------
  |  |  130|      0|#define TIFF_NOBITREV 0x00100U    /* inhibit bit reversal logic */
  ------------------
  |  Branch (1065:13): [True: 0, False: 0]
  ------------------
 1066|      0|            TIFFReverseBits((uint8_t *)tif->tif_rawdata, tif->tif_rawcc);
 1067|      0|        if (!TIFFAppendToStrip(tif,
  ------------------
  |  Branch (1067:13): [True: 0, False: 0]
  ------------------
 1068|      0|                               isTiled(tif) ? tif->tif_dir.td_curtile
  ------------------
  |  |  282|      0|#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  |  |  ------------------
  |  |  |  |  132|      0|#define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
  |  |  ------------------
  |  |  |  Branch (282:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1069|      0|                                            : tif->tif_dir.td_curstrip,
 1070|      0|                               tif->tif_rawdata, tif->tif_rawcc))
 1071|      0|        {
 1072|       |            /* We update those variables even in case of error since there's */
 1073|       |            /* code that doesn't really check the return code of this */
 1074|       |            /* function */
 1075|      0|            tif->tif_rawcc = 0;
 1076|      0|            tif->tif_rawcp = tif->tif_rawdata;
 1077|      0|            return (0);
 1078|      0|        }
 1079|      0|        tif->tif_rawcc = 0;
 1080|      0|        tif->tif_rawcp = tif->tif_rawdata;
 1081|      0|    }
 1082|    207|    return (1);
 1083|    207|}
tif_write.c:_TIFFReserveLargeEnoughWriteBuffer:
  219|    207|{
  220|    207|    static const char module[] = "_TIFFReserveLargeEnoughWriteBuffer";
  221|    207|    TIFFDirectory *td = &tif->tif_dir;
  222|       |
  223|    207|    if (td->td_stripbytecount_p == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 207]
  ------------------
  224|      0|    {
  225|      0|        TIFFErrorExtR(tif, module, "Strip bytecount array pointer is NULL");
  226|      0|        return 0;
  227|      0|    }
  228|       |
  229|    207|    if (strip_or_tile == NOSTRIP || strip_or_tile >= td->td_nstrips)
  ------------------
  |  |   35|    414|#define NOSTRIP ((uint32_t)(-1)) /* undefined state */
  ------------------
  |  Branch (229:9): [True: 0, False: 207]
  |  Branch (229:37): [True: 0, False: 207]
  ------------------
  230|      0|    {
  231|      0|        TIFFErrorExtR(tif, module, "Strip/tile number not valid");
  232|      0|        return 0;
  233|      0|    }
  234|       |
  235|    207|    if (td->td_stripbytecount_p[strip_or_tile] > 0)
  ------------------
  |  Branch (235:9): [True: 0, False: 207]
  ------------------
  236|      0|    {
  237|       |        /* The +1 is to ensure at least one extra bytes */
  238|       |        /* The +4 is because the LZW encoder flushes 4 bytes before the limit */
  239|      0|        uint64_t safe_buffer_size =
  240|      0|            (uint64_t)(td->td_stripbytecount_p[strip_or_tile] + 1 + 4);
  241|      0|        if (tif->tif_rawdatasize <= (tmsize_t)safe_buffer_size)
  ------------------
  |  Branch (241:13): [True: 0, False: 0]
  ------------------
  242|      0|        {
  243|      0|            if (!(TIFFWriteBufferSetup(
  ------------------
  |  Branch (243:17): [True: 0, False: 0]
  ------------------
  244|      0|                    tif, NULL,
  245|      0|                    (tmsize_t)TIFFroundup_64(safe_buffer_size, 1024))))
  ------------------
  |  |  331|      0|#define TIFFroundup_64(x, y) ((uint64_t)(TIFFhowmany_64(x, y) * (uint64_t)(y)))
  |  |  ------------------
  |  |  |  |  328|      0|    ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
  |  |  ------------------
  ------------------
  246|      0|                return 0;
  247|      0|        }
  248|      0|    }
  249|    207|    return 1;
  250|    207|}
tif_write.c:TIFFAppendToStrip:
  870|    207|{
  871|    207|    static const char module[] = "TIFFAppendToStrip";
  872|    207|    TIFFDirectory *td = &tif->tif_dir;
  873|    207|    uint64_t m;
  874|    207|    int64_t old_byte_count = -1;
  875|       |
  876|       |    /* Some security checks */
  877|    207|    if (td->td_stripoffset_p == NULL)
  ------------------
  |  Branch (877:9): [True: 0, False: 207]
  ------------------
  878|      0|    {
  879|      0|        TIFFErrorExtR(tif, module, "Strip offset array pointer is NULL");
  880|      0|        return (0);
  881|      0|    }
  882|    207|    if (td->td_stripbytecount_p == NULL)
  ------------------
  |  Branch (882:9): [True: 0, False: 207]
  ------------------
  883|      0|    {
  884|      0|        TIFFErrorExtR(tif, module, "Strip bytecount array pointer is NULL");
  885|      0|        return (0);
  886|      0|    }
  887|    207|    if (strip == NOSTRIP)
  ------------------
  |  |   35|    207|#define NOSTRIP ((uint32_t)(-1)) /* undefined state */
  ------------------
  |  Branch (887:9): [True: 0, False: 207]
  ------------------
  888|      0|    {
  889|      0|        TIFFErrorExtR(tif, module, "Strip number not valid (NOSTRIP)");
  890|      0|        return (0);
  891|      0|    }
  892|    207|    if (strip >= td->td_nstrips)
  ------------------
  |  Branch (892:9): [True: 0, False: 207]
  ------------------
  893|      0|    {
  894|      0|        TIFFErrorExtR(tif, module, "%lu: Strip out of range, max %lu",
  895|      0|                      (unsigned long)strip, (unsigned long)td->td_nstrips);
  896|      0|        return (0);
  897|      0|    }
  898|       |
  899|    207|    if (tif->tif_curoff == 0)
  ------------------
  |  Branch (899:9): [True: 207, False: 0]
  ------------------
  900|    207|        tif->tif_lastvalidoff = 0;
  901|       |
  902|    207|    if (td->td_stripoffset_p[strip] == 0 || tif->tif_curoff == 0)
  ------------------
  |  Branch (902:9): [True: 207, False: 0]
  |  Branch (902:45): [True: 0, False: 0]
  ------------------
  903|    207|    {
  904|    207|        assert(td->td_nstrips > 0);
  ------------------
  |  Branch (904:9): [True: 0, False: 207]
  |  Branch (904:9): [True: 207, False: 0]
  ------------------
  905|       |
  906|    207|        if (td->td_stripbytecount_p[strip] != 0 &&
  ------------------
  |  Branch (906:13): [True: 0, False: 207]
  ------------------
  907|      0|            td->td_stripoffset_p[strip] != 0 &&
  ------------------
  |  Branch (907:13): [True: 0, False: 0]
  ------------------
  908|      0|            td->td_stripbytecount_p[strip] >= (uint64_t)cc)
  ------------------
  |  Branch (908:13): [True: 0, False: 0]
  ------------------
  909|      0|        {
  910|       |            /*
  911|       |             * There is already tile data on disk, and the new tile
  912|       |             * data we have will fit in the same space.  The only
  913|       |             * aspect of this that is risky is that there could be
  914|       |             * more data to append to this strip before we are done
  915|       |             * depending on how we are getting called.
  916|       |             */
  917|      0|            if (!SeekOK(tif, td->td_stripoffset_p[strip]))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
  |  Branch (917:17): [True: 0, False: 0]
  ------------------
  918|      0|            {
  919|      0|                TIFFErrorExtR(tif, module, "Seek error at scanline %lu",
  920|      0|                              (unsigned long)tif->tif_dir.td_row);
  921|      0|                return (0);
  922|      0|            }
  923|       |
  924|      0|            tif->tif_lastvalidoff =
  925|      0|                td->td_stripoffset_p[strip] + td->td_stripbytecount_p[strip];
  926|      0|        }
  927|    207|        else
  928|    207|        {
  929|       |            /*
  930|       |             * Seek to end of file, and set that as our location to
  931|       |             * write this strip.
  932|       |             */
  933|    207|            td->td_stripoffset_p[strip] = TIFFSeekFile(tif, 0, SEEK_END);
  ------------------
  |  |  291|    207|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  934|    207|            tif->tif_flags |= TIFF_DIRTYSTRIP;
  ------------------
  |  |  145|    207|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
  935|    207|        }
  936|       |
  937|    207|        tif->tif_curoff = td->td_stripoffset_p[strip];
  938|       |
  939|       |        /*
  940|       |         * We are starting a fresh strip/tile, so set the size to zero.
  941|       |         */
  942|    207|        old_byte_count = (int64_t)td->td_stripbytecount_p[strip];
  943|    207|        td->td_stripbytecount_p[strip] = 0;
  944|    207|    }
  945|       |
  946|    207|    m = tif->tif_curoff + (uint64_t)cc;
  947|    207|    if (!(tif->tif_flags & TIFF_BIGTIFF))
  ------------------
  |  |  143|    207|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (947:9): [True: 207, False: 0]
  ------------------
  948|    207|        m = (uint32_t)m;
  949|    207|    if ((m < tif->tif_curoff) || (m < (uint64_t)cc))
  ------------------
  |  Branch (949:9): [True: 0, False: 207]
  |  Branch (949:34): [True: 0, False: 207]
  ------------------
  950|      0|    {
  951|      0|        TIFFErrorExtR(tif, module, "Maximum TIFF file size exceeded");
  952|      0|        return (0);
  953|      0|    }
  954|       |
  955|    207|    if (tif->tif_lastvalidoff != 0 && m > tif->tif_lastvalidoff &&
  ------------------
  |  Branch (955:9): [True: 0, False: 207]
  |  Branch (955:39): [True: 0, False: 0]
  ------------------
  956|      0|        td->td_stripbytecount_p[strip] > 0)
  ------------------
  |  Branch (956:9): [True: 0, False: 0]
  ------------------
  957|      0|    {
  958|       |        /* Ouch: we have detected that we are rewriting in place a strip/tile */
  959|       |        /* with several calls to TIFFAppendToStrip(). The first call was with */
  960|       |        /* a size smaller than the previous size of the strip/tile, so we */
  961|       |        /* opted to rewrite in place, but a following call causes us to go */
  962|       |        /* outsize of the strip/tile area, so we have to finally go for a */
  963|       |        /* append-at-end-of-file strategy, and start by moving what we already
  964|       |         */
  965|       |        /* wrote. */
  966|      0|        tmsize_t tempSize;
  967|      0|        void *temp;
  968|      0|        uint64_t offsetRead;
  969|      0|        uint64_t offsetWrite;
  970|      0|        uint64_t toCopy = td->td_stripbytecount_p[strip];
  971|       |
  972|      0|        if (toCopy < 1024 * 1024)
  ------------------
  |  Branch (972:13): [True: 0, False: 0]
  ------------------
  973|      0|            tempSize = (tmsize_t)toCopy;
  974|      0|        else
  975|      0|            tempSize = 1024 * 1024;
  976|       |
  977|      0|        offsetRead = td->td_stripoffset_p[strip];
  978|      0|        offsetWrite = TIFFSeekFile(tif, 0, SEEK_END);
  ------------------
  |  |  291|      0|    ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  ------------------
  979|       |
  980|      0|        m = offsetWrite + (uint64_t)toCopy + (uint64_t)cc;
  981|      0|        if (!(tif->tif_flags & TIFF_BIGTIFF) && m != (uint32_t)m)
  ------------------
  |  |  143|      0|#define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
  ------------------
  |  Branch (981:13): [True: 0, False: 0]
  |  Branch (981:49): [True: 0, False: 0]
  ------------------
  982|      0|        {
  983|      0|            TIFFErrorExtR(tif, module, "Maximum TIFF file size exceeded");
  984|      0|            return (0);
  985|      0|        }
  986|       |
  987|      0|        temp = _TIFFmallocExt(tif, tempSize);
  988|      0|        if (temp == NULL)
  ------------------
  |  Branch (988:13): [True: 0, False: 0]
  ------------------
  989|      0|        {
  990|      0|            TIFFErrorExtR(tif, module, "No space for output buffer");
  991|      0|            return (0);
  992|      0|        }
  993|       |
  994|      0|        tif->tif_flags |= TIFF_DIRTYSTRIP;
  ------------------
  |  |  145|      0|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
  995|       |
  996|      0|        td->td_stripoffset_p[strip] = offsetWrite;
  997|      0|        td->td_stripbytecount_p[strip] = 0;
  998|       |
  999|       |        /* Move data written by previous calls to us at end of file */
 1000|      0|        while (toCopy > 0)
  ------------------
  |  Branch (1000:16): [True: 0, False: 0]
  ------------------
 1001|      0|        {
 1002|      0|            tmsize_t chunkSize =
 1003|      0|                toCopy < (uint64_t)tempSize ? (tmsize_t)toCopy : tempSize;
  ------------------
  |  Branch (1003:17): [True: 0, False: 0]
  ------------------
 1004|      0|            if (!SeekOK(tif, offsetRead))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
  |  Branch (1004:17): [True: 0, False: 0]
  ------------------
 1005|      0|            {
 1006|      0|                TIFFErrorExtR(tif, module, "Seek error");
 1007|      0|                _TIFFfreeExt(tif, temp);
 1008|      0|                return (0);
 1009|      0|            }
 1010|      0|            if (!ReadOK(tif, temp, chunkSize))
  ------------------
  |  |  304|      0|    (TIFFReadFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  287|      0|    ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (1010:17): [True: 0, False: 0]
  ------------------
 1011|      0|            {
 1012|      0|                TIFFErrorExtR(tif, module, "Cannot read");
 1013|      0|                _TIFFfreeExt(tif, temp);
 1014|      0|                return (0);
 1015|      0|            }
 1016|      0|            if (!SeekOK(tif, offsetWrite))
  ------------------
  |  |  307|      0|#define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  ------------------
  |  Branch (1016:17): [True: 0, False: 0]
  ------------------
 1017|      0|            {
 1018|      0|                TIFFErrorExtR(tif, module, "Seek error");
 1019|      0|                _TIFFfreeExt(tif, temp);
 1020|      0|                return (0);
 1021|      0|            }
 1022|      0|            if (!WriteOK(tif, temp, chunkSize))
  ------------------
  |  |  311|      0|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|      0|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (1022:17): [True: 0, False: 0]
  ------------------
 1023|      0|            {
 1024|      0|                TIFFErrorExtR(tif, module, "Cannot write");
 1025|      0|                _TIFFfreeExt(tif, temp);
 1026|      0|                return (0);
 1027|      0|            }
 1028|      0|            offsetRead += (uint64_t)chunkSize;
 1029|      0|            offsetWrite += (uint64_t)chunkSize;
 1030|      0|            td->td_stripbytecount_p[strip] += (uint64_t)chunkSize;
 1031|      0|            toCopy -= (uint64_t)chunkSize;
 1032|      0|        }
 1033|      0|        _TIFFfreeExt(tif, temp);
 1034|       |
 1035|       |        /* Append the data of this call */
 1036|      0|        offsetWrite += (uint64_t)cc;
 1037|      0|        m = offsetWrite;
 1038|      0|    }
 1039|       |
 1040|    207|    if (!WriteOK(tif, data, cc))
  ------------------
  |  |  311|    207|    (TIFFWriteFile((tif), (buf), (size)) == (tmsize_t)(size))
  |  |  ------------------
  |  |  |  |  289|    207|    ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  |  |  ------------------
  ------------------
  |  Branch (1040:9): [True: 0, False: 207]
  ------------------
 1041|      0|    {
 1042|      0|        TIFFErrorExtR(tif, module, "Write error at scanline %lu",
 1043|      0|                      (unsigned long)tif->tif_dir.td_row);
 1044|      0|        return (0);
 1045|      0|    }
 1046|    207|    tif->tif_curoff = m;
 1047|    207|    td->td_stripbytecount_p[strip] += (uint64_t)cc;
 1048|       |
 1049|    207|    if ((int64_t)td->td_stripbytecount_p[strip] != old_byte_count)
  ------------------
  |  Branch (1049:9): [True: 207, False: 0]
  ------------------
 1050|    207|        tif->tif_flags |= TIFF_DIRTYSTRIP;
  ------------------
  |  |  145|    207|#define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  ------------------
 1051|       |
 1052|    207|    return (1);
 1053|    207|}

