contrib/addtiffo/tif_ovrcache.c:257: error: Buffer Overrun L3
  Offset: [7, +oo] (⇐ [0, +oo] + 7) Size: [0, +oo] by call to `TIFFFlush`.

contrib/addtiffo/tif_ovrcache.c:235:5: Call
233. 				if ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)
234. 					RowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;
235. 				TIFFWriteEncodedStrip( psCache->hTIFF, nTileID,
         ^
236. 				    pabyData,
237. 				    TIFFVStripSize(psCache->hTIFF,RowsInStrip) );

libtiff/tif_write.c:187:1: Parameter `*tif->tif_dir.td_stripbytecount`
  185.  * NB: Image length must be setup before writing.
  186.  */
  187. tmsize_t
       ^
  188. TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
  189. {

contrib/addtiffo/tif_ovrcache.c:257:5: Call
255. /*      Restore access to original directory.                           */
256. /* -------------------------------------------------------------------- */
257.     TIFFFlush( psCache->hTIFF );
         ^
258.     /* TODO: add checks on error status return of TIFFFlush */
259.     TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );

libtiff/tif_flush.c:32:1: Parameter `*tif->tif_dir.td_stripbytecount`
  30. #include "tiffiop.h"
  31. 
  32. int
      ^
  33. TIFFFlush(TIFF* tif)
  34. {

libtiff/tif_flush.c:83:13: Call
  81. 
  82.     if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP)) 
  83.         && !TIFFRewriteDirectory(tif))
                  ^
  84.         return (0);
  85. 

libtiff/tif_dirwrite.c:217:1: Parameter `*tif->tif_dir.td_stripbytecount`
    215.  * previously used directory space. 
    216.  */ 
    217. int
         ^
    218. TIFFRewriteDirectory( TIFF *tif )
    219. {

libtiff/tif_dirwrite.c:224:10: Call
    222. 	/* We don't need to do anything special if it hasn't been written. */
    223. 	if( tif->tif_diroff == 0 )
    224. 		return TIFFWriteDirectory( tif );
                  ^
    225. 
    226. 	/*

libtiff/tif_dirwrite.c:181:1: Parameter `*tif->tif_dir.td_stripbytecount`
      179.  * storage that's been changed.
      180.  */
      181. int
           ^
      182. TIFFWriteDirectory(TIFF* tif)
      183. {

libtiff/tif_dirwrite.c:184:9: Call
      182. TIFFWriteDirectory(TIFF* tif)
      183. {
      184. 	return TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);
                   ^
      185. }
      186. 

libtiff/tif_dirwrite.c:363:1: Parameter `*tif->tif_dir.td_stripbytecount`
        361. }
        362. 
        363. static int
             ^
        364. TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
        365. {

libtiff/tif_dirwrite.c:533:11: Call
        531. 				if (!isTiled(tif))
        532. 				{
        533. 					if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))
                       ^
        534. 						goto bad;
        535. 				}

libtiff/tif_dirwrite.c:1670:1: Parameter `*value`
          1668. /************************************************************************/
          1669. 
          1670. static int
                ^
          1671. TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)
          1672. {

libtiff/tif_dirwrite.c:1689:16: Call
          1687.     /* We always write LONG8 for BigTIFF, no checking needed. */
          1688.     if( tif->tif_flags&TIFF_BIGTIFF )
          1689.         return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,
                               ^
          1690.                                                       tag,count,value);
          1691. 

libtiff/tif_dirwrite.c:2137:1: Parameter `*value`
            2135. #endif
            2136. 
            2137. static int
                  ^
            2138. TIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)
            2139. {

libtiff/tif_dirwrite.c:2147:3: Call
            2145. 	}
            2146. 	if (tif->tif_flags&TIFF_SWAB)
            2147. 		TIFFSwabArrayOfLong8(value,count);
                    ^
            2148. 	return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,count,count*8,value));
            2149. }

libtiff/tif_swab.c:121:1: <Length trace>
119. 
120. #if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfLong8)
121. void
     ^
122. TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)
123. {

libtiff/tif_swab.c:121:1: Parameter `*lp`
              119. 
              120. #if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfLong8)
              121. void
                   ^
              122. TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)
              123. {

libtiff/tif_swab.c:129:3: Assignment
              127. 	/* XXX unroll loop some */
              128. 	while (n-- > 0) {
              129. 		cp = (unsigned char *)lp;
                     ^
              130. 		t = cp[7]; cp[7] = cp[0]; cp[0] = t;
              131. 		t = cp[6]; cp[6] = cp[1]; cp[1] = t;

libtiff/tif_swab.c:130:7: Array access: Offset: [7, +oo] (⇐ [0, +oo] + 7) Size: [0, +oo] by call to `TIFFFlush` 
              128. 	while (n-- > 0) {
              129. 		cp = (unsigned char *)lp;
              130. 		t = cp[7]; cp[7] = cp[0]; cp[0] = t;
                         ^
              131. 		t = cp[6]; cp[6] = cp[1]; cp[1] = t;
              132. 		t = cp[5]; cp[5] = cp[2]; cp[2] = t;

void
TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)
{
	register unsigned char *cp;
	register unsigned char t;
	assert(sizeof(uint64)==8);
	while (n-- > 0) {
		cp = (unsigned char *)lp;
		t = cp[7]; cp[7] = cp[0]; cp[0] = t;
		t = cp[6]; cp[6] = cp[1]; cp[1] = t;
		t = cp[5]; cp[5] = cp[2]; cp[2] = t;
		t = cp[4]; cp[4] = cp[3]; cp[3] = t;
		lp++;
	}
}
['static void TIFFWriteOvrRow( TIFFOvrCache * psCache )\n{\n    int\t\tnRet, iTileX, iTileY = psCache->nBlockOffset;\n    unsigned char *pabyData;\n    toff_t\tnBaseDirOffset;\n    uint32      RowsInStrip;\n    if( TIFFIsByteSwapped(psCache->hTIFF) )\n    {\n        if( psCache->nBitsPerPixel == 16 )\n            TIFFSwabArrayOfShort( (uint16 *) psCache->pabyRow1Blocks,\n                      (psCache->nBytesPerBlock * psCache->nSamples) / 2 );\n        else if( psCache->nBitsPerPixel == 32 )\n            TIFFSwabArrayOfLong( (uint32 *) psCache->pabyRow1Blocks,\n                         (psCache->nBytesPerBlock * psCache->nSamples) / 4 );\n        else if( psCache->nBitsPerPixel == 64 )\n            TIFFSwabArrayOfDouble( (double *) psCache->pabyRow1Blocks,\n                         (psCache->nBytesPerBlock * psCache->nSamples) / 8 );\n    }\n    nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );\n    nRet = TIFFSetSubDirectory( psCache->hTIFF, psCache->nDirOffset );\n    assert( nRet == 1 );\n\tfor( iTileX = 0; iTileX < psCache->nBlocksPerRow; iTileX++ )\n\t{\n\t\tint nTileID;\n\t\tif (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)\n\t\t{\n\t\t\tint iSample;\n\t\t\tfor( iSample = 0; iSample < psCache->nSamples; iSample++ )\n\t\t\t{\n\t\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, iSample );\n\t\t\t\tif( psCache->bTiled )\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t\t    iTileX * psCache->nBlockXSize,\n\t\t\t\t\t    iTileY * psCache->nBlockYSize,\n\t\t\t\t\t    0, (tsample_t) iSample );\n\t\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t\t    pabyData,\n\t\t\t\t\t    TIFFTileSize(psCache->hTIFF) );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t\t    iTileY * psCache->nBlockYSize,\n\t\t\t\t\t    (tsample_t) iSample );\n\t\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t\t    pabyData,\n\t\t\t\t\t    TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, 0 );\n\t\t\tif( psCache->bTiled )\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t    iTileX * psCache->nBlockXSize,\n\t\t\t\t    iTileY * psCache->nBlockYSize,\n\t\t\t\t    0, 0 );\n\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t    pabyData,\n\t\t\t\t    TIFFTileSize(psCache->hTIFF) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t    iTileY * psCache->nBlockYSize,\n\t\t\t\t    0 );\n\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t    pabyData,\n\t\t\t\t    TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t}\n\t\t}\n\t}\n    pabyData = psCache->pabyRow1Blocks;\n    psCache->pabyRow1Blocks = psCache->pabyRow2Blocks;\n    psCache->pabyRow2Blocks = pabyData;\n    _TIFFmemset( pabyData, 0, psCache->nBytesPerRow );\n    psCache->nBlockOffset++;\n    TIFFFlush( psCache->hTIFF );\n    TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );\n}', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t    TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n        tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n        if (td->td_stripsperimage == 0) {\n                TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");\n                return ((tmsize_t) -1);\n        }\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\tif( td->td_stripbytecount[strip] > 0 )\n        {\n            if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )\n            {\n                if( !(TIFFWriteBufferSetup(tif, NULL,\n                    (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )\n                    return ((tmsize_t)(-1));\n            }\n            tif->tif_curoff = 0;\n        }\n    tif->tif_rawcc = 0;\n    tif->tif_rawcp = tif->tif_rawdata;\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n    if( td->td_compression == COMPRESSION_NONE )\n    {\n        tif->tif_postdecode( tif, (uint8*) data, cc );\n        if (!isFillOrder(tif, td->td_fillorder) &&\n            (tif->tif_flags & TIFF_NOBITREV) == 0)\n            TIFFReverseBits((uint8*) data, cc);\n        if (cc > 0 &&\n            !TIFFAppendToStrip(tif, strip, (uint8*) data, cc))\n            return ((tmsize_t) -1);\n        return (cc);\n    }\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn ((tmsize_t) -1);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t    (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t    !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n    if( tif->tif_mode == O_RDONLY )\n        return 1;\n    if (!TIFFFlushData(tif))\n        return (0);\n    if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n        && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n        && tif->tif_mode == O_RDWR )\n    {\n        uint64  *offsets=NULL, *sizes=NULL;\n        if( TIFFIsTiled(tif) )\n        {\n            if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )\n                && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )\n                && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,\n                                      tif->tif_dir.td_nstrips, offsets )\n                && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,\n                                      tif->tif_dir.td_nstrips, sizes ) )\n            {\n                tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n                tif->tif_flags &= ~TIFF_BEENWRITING;\n                return 1;\n            }\n        }\n        else\n        {\n            if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )\n                && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )\n                && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,\n                                      tif->tif_dir.td_nstrips, offsets )\n                && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,\n                                      tif->tif_dir.td_nstrips, sizes ) )\n            {\n                tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n                tif->tif_flags &= ~TIFF_BEENWRITING;\n                return 1;\n            }\n        }\n    }\n    if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n        && !TIFFRewriteDirectory(tif))\n        return (0);\n    return (1);\n}', 'int\nTIFFRewriteDirectory( TIFF *tif )\n{\n\tstatic const char module[] = "TIFFRewriteDirectory";\n\tif( tif->tif_diroff == 0 )\n\t\treturn TIFFWriteDirectory( tif );\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tif (tif->tif_header.classic.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.classic.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,4,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t    "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint32 nextdir;\n\t\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint32 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t    !ReadOK(tif, &dircount, 2)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabShort(&dircount);\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t    nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 4)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint32 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t    nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 4)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t     "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (tif->tif_header.big.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.big.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,8,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t    "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint64 nextdir;\n\t\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint64 dircount64;\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint64 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t    !ReadOK(tif, &dircount64, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&dircount64);\n\t\t\t\tif (dircount64>0xFFFF)\n\t\t\t\t{\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "Sanity check on tag count failed, likely corrupt TIFF");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tdircount=(uint16)dircount64;\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t    nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t     "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint64 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t    nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 8)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t     "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\treturn TIFFWriteDirectory( tif );\n}', 'int\nTIFFWriteDirectory(TIFF* tif)\n{\n\treturn TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);\n}', 'static int\nTIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)\n{\n\tstatic const char module[] = "TIFFWriteDirectorySec";\n\tuint32 ndir;\n\tTIFFDirEntry* dir;\n\tuint32 dirsize;\n\tvoid* dirmem;\n\tuint32 m;\n\tif (tif->tif_mode == O_RDONLY)\n\t\treturn (1);\n        _TIFFFillStriles( tif );\n\tif (imagedone)\n\t{\n\t\tif (tif->tif_flags & TIFF_POSTENCODE)\n\t\t{\n\t\t\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\t\t\tif (!(*tif->tif_postencode)(tif))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t    "Error post-encoding before directory write");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\t(*tif->tif_close)(tif);\n\t\tif (tif->tif_rawcc > 0\n\t\t    && (tif->tif_flags & TIFF_BEENWRITING) != 0 )\n\t\t{\n\t\t    if( !TIFFFlushData1(tif) )\n                    {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "Error flushing data before directory write");\n\t\t\treturn (0);\n                    }\n\t\t}\n\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t{\n\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_rawdata = NULL;\n\t\t\ttif->tif_rawcc = 0;\n\t\t\ttif->tif_rawdatasize = 0;\n                        tif->tif_rawdataoff = 0;\n                        tif->tif_rawdataloaded = 0;\n\t\t}\n\t\ttif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);\n\t}\n\tdir=NULL;\n\tdirmem=NULL;\n\tdirsize=0;\n\twhile (1)\n\t{\n\t\tndir=0;\n\t\tif (isimage)\n\t\t{\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_POSITION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBFILETYPE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COMPRESSION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_THRESHHOLDING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_FILLORDER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ORIENTATION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PLANARCONFIG))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PAGENUMBER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPOFFSETS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n                    if (tif->tif_dir.td_stripoffset != NULL &&\n                        !TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n                        goto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COLORMAP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_EXTRASAMPLES))\n\t\t\t{\n\t\t\t\tif (tif->tif_dir.td_extrasamples)\n\t\t\t\t{\n\t\t\t\t\tuint16 na;\n\t\t\t\t\tuint16* nb;\n\t\t\t\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb);\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_REFBLACKWHITE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_INKNAMES))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\t{\n\t\t\t\tuint32 n;\n\t\t\t\tfor (n=0; n<tif->tif_nfields; n++) {\n\t\t\t\t\tconst TIFFField* o;\n\t\t\t\t\to = tif->tif_fields[n];\n\t\t\t\t\tif ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit)))\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (o->get_field_type)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase TIFF_SETGET_ASCII:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tchar* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_ASCII);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pb);\n\t\t\t\t\t\t\t\t\tpa=(uint32)(strlen(pb));\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT16:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint16 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_SHORT);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT32:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_LONG);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_C32_UINT8:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tvoid* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_UNDEFINED);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE2);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==1);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pa,&pb);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tassert(0);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++)\n\t\t{\n                        uint16 tag = (uint16)tif->tif_dir.td_customValues[m].info->field_tag;\n                        uint32 count = tif->tif_dir.td_customValues[m].count;\n\t\t\tswitch (tif->tif_dir.td_customValues[m].info->field_type)\n\t\t\t{\n\t\t\t\tcase TIFF_ASCII:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert(0);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (dir!=NULL)\n\t\t\tbreak;\n\t\tdir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry));\n\t\tif (dir==NULL)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (isimage)\n\t\t{\n\t\t\tif ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif)))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse\n\t\t\ttif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~((toff_t)1));\n\t\tif (pdiroff!=NULL)\n\t\t\t*pdiroff=tif->tif_diroff;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\tdirsize=2+ndir*12+4;\n\t\telse\n\t\t\tdirsize=8+ndir*20+8;\n\t\ttif->tif_dataoff=tif->tif_diroff+dirsize;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\ttif->tif_dataoff=(uint32)tif->tif_dataoff;\n\t\tif ((tif->tif_dataoff<tif->tif_diroff)||(tif->tif_dataoff<(uint64)dirsize))\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (tif->tif_dataoff&1)\n\t\t\ttif->tif_dataoff++;\n\t\tif (isimage)\n\t\t\ttif->tif_curdir++;\n\t}\n\tif (isimage)\n\t{\n\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0))\n\t\t{\n\t\t\tuint32 na;\n\t\t\tTIFFDirEntry* nb;\n\t\t\tfor (na=0, nb=dir; ; na++, nb++)\n\t\t\t{\n\t\t\t\tif( na == ndir )\n                                {\n                                    TIFFErrorExt(tif->tif_clientdata,module,\n                                                 "Cannot find SubIFD tag");\n                                    goto bad;\n                                }\n\t\t\t\tif (nb->tdir_tag==TIFFTAG_SUBIFD)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+2+na*12+8;\n\t\t\telse\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+8+na*20+12;\n\t\t}\n\t}\n\tdirmem=_TIFFmalloc(dirsize);\n\tif (dirmem==NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\tgoto bad;\n\t}\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tuint8* n;\n\t\tuint32 nTmp;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint16*)n=(uint16)ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabShort((uint16*)n);\n\t\tn+=2;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\tnTmp = (uint32)o->tdir_count;\n\t\t\t_TIFFmemcpy(n,&nTmp,4);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong((uint32*)n);\n\t\t\tn+=4;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,4);\n\t\t\tn+=4;\n\t\t\to++;\n\t\t}\n\t\tnTmp = (uint32)tif->tif_nextdiroff;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong(&nTmp);\n\t\t_TIFFmemcpy(n,&nTmp,4);\n\t}\n\telse\n\t{\n\t\tuint8* n;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint64*)n=ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t\tn+=8;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t_TIFFmemcpy(n,&o->tdir_count,8);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong8((uint64*)n);\n\t\t\tn+=8;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,8);\n\t\t\tn+=8;\n\t\t\to++;\n\t\t}\n\t\t_TIFFmemcpy(n,&tif->tif_nextdiroff,8);\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t}\n\t_TIFFfree(dir);\n\tdir=NULL;\n\tif (!SeekOK(tif,tif->tif_diroff))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\tif (!WriteOK(tif,dirmem,(tmsize_t)dirsize))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\t_TIFFfree(dirmem);\n\tif (imagedone)\n\t{\n\t\tTIFFFreeDirectory(tif);\n\t\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\t\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\t\t(*tif->tif_cleanup)(tif);\n\t\tTIFFCreateDirectory(tif);\n\t}\n\treturn(1);\nbad:\n\tif (dir!=NULL)\n\t\t_TIFFfree(dir);\n\tif (dirmem!=NULL)\n\t\t_TIFFfree(dirmem);\n\treturn(0);\n}', 'static int\nTIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)\n{\n    static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";\n    uint64* ma;\n    uint32 mb;\n    uint32* p;\n    uint32* q;\n    int o;\n    if (dir==NULL)\n    {\n        (*ndir)++;\n        return(1);\n    }\n    if( tif->tif_flags&TIFF_BIGTIFF )\n        return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,\n                                                      tag,count,value);\n    p = _TIFFmalloc(count*sizeof(uint32));\n    if (p==NULL)\n    {\n        TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n        return(0);\n    }\n    for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)\n    {\n        if (*ma>0xFFFFFFFF)\n        {\n            TIFFErrorExt(tif->tif_clientdata,module,\n                         "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file.");\n            _TIFFfree(p);\n            return(0);\n        }\n        *q= (uint32)(*ma);\n    }\n    o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p);\n    _TIFFfree(p);\n    return(o);\n}', 'static int\nTIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)\n{\n\tassert(count<0x20000000);\n\tassert(sizeof(uint64)==8);\n\tif( !(tif->tif_flags&TIFF_BIGTIFF) ) {\n\t\tTIFFErrorExt(tif->tif_clientdata,"TIFFWriteDirectoryTagCheckedLong8Array","LONG8 not allowed for ClassicTIFF");\n\t\treturn(0);\n\t}\n\tif (tif->tif_flags&TIFF_SWAB)\n\t\tTIFFSwabArrayOfLong8(value,count);\n\treturn(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,count,count*8,value));\n}', 'void\nTIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)\n{\n\tregister unsigned char *cp;\n\tregister unsigned char t;\n\tassert(sizeof(uint64)==8);\n\twhile (n-- > 0) {\n\t\tcp = (unsigned char *)lp;\n\t\tt = cp[7]; cp[7] = cp[0]; cp[0] = t;\n\t\tt = cp[6]; cp[6] = cp[1]; cp[1] = t;\n\t\tt = cp[5]; cp[5] = cp[2]; cp[2] = t;\n\t\tt = cp[4]; cp[4] = cp[3]; cp[3] = t;\n\t\tlp++;\n\t}\n}']