tools/tiffcrop.c:6691: error: Integer Overflow L2
  ([min(1, `out->tif_dir.td_imagedepth`), 4294967294] + [0, 4294967294-min(1, `out->tif_dir.td_imagedepth`)]):unsigned32 by call to `writeSingleSection`.

tools/tiffcrop.c:6649:1: Parameter `out->tif_dir.td_imagedepth`
6647.   } /* end writeRegions */
6648. 
6649. static int
      ^
6650. writeImageSections(TIFF *in, TIFF *out, struct image_data *image,
6651. 		   struct pagedef *page, struct pageseg *sections,

tools/tiffcrop.c:6691:9: Call
6689. 
6690.   /* call the write routine here instead of outside the loop */
6691.     if (writeSingleSection(in, out, image, dump, width, length, hres, vres, sect_buff))
              ^
6692.       {
6693.       TIFFError("writeImageSections", "Unable to write image section");

tools/tiffcrop.c:6707:1: Parameter `out->tif_dir.td_imagedepth`
  6705.  * original code assumes we are always copying all samples.
  6706.  */
  6707. static int  
        ^
  6708. writeSingleSection(TIFF *in, TIFF *out, struct image_data *image,
  6709.                    struct dump_opts *dump, uint32 width, uint32 length,

tools/tiffcrop.c:6958:7: Call
  6956.     {
  6957.     if (config == PLANARCONFIG_CONTIG)
  6958.       writeBufferToContigStrips (out, sect_buff, length);
              ^
  6959.     else
  6960.       writeBufferToSeparateStrips(out, sect_buff, length, width, spp, dump);

tools/tiffcrop.c:1086:1: Parameter `out->tif_dir.td_imagedepth`
    1084.   }
    1085. 
    1086. static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength)
          ^
    1087.   {
    1088.   uint32 row, nrows, rowsperstrip;

tools/tiffcrop.c:1098:9: Call
    1096. 	     imagelength - row : rowsperstrip;
    1097.     stripsize = TIFFVStripSize(out, nrows);
    1098.     if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0)
                  ^
    1099.       {
    1100.       TIFFError(TIFFFileName(out), "Error, can't write strip %u", strip - 1);

libtiff/tif_write.c:183:1: Parameter `tif->tif_dir.td_imagedepth`
      181.  * NB: Image length must be setup before writing.
      182.  */
      183. tmsize_t
           ^
      184. TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
      185. {

libtiff/tif_write.c:190:7: Call
      188. 	uint16 sample;
      189. 
      190. 	if (!WRITECHECKSTRIPS(tif, module))
                 ^
      191. 		return ((tmsize_t) -1);
      192. 	/*

libtiff/tif_write.c:488:1: Parameter `tif->tif_dir.td_imagedepth`
        486.  * that important information is not changed.
        487.  */
        488. int
             ^
        489. TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
        490. {

libtiff/tif_write.c:533:46: Call
        531. 		}
        532. 	}
        533. 	if (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {
                                                          ^
        534. 		tif->tif_dir.td_nstrips = 0;
        535. 		TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",

libtiff/tif_write.c:448:1: Parameter `tif->tif_dir.td_imagedepth`
          446.     (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
          447. 
          448. int
               ^
          449. TIFFSetupStrips(TIFF* tif)
          450. {

libtiff/tif_write.c:456:29: Call
          454. 		td->td_stripsperimage =
          455. 		    isUnspecified(tif, FIELD_TILEDIMENSIONS) ?
          456. 			td->td_samplesperpixel : TIFFNumberOfTiles(tif);
                                           ^
          457. 	else
          458. 		td->td_stripsperimage =

libtiff/tif_tile.c:140:1: <LHS trace>
138.  * Compute how many tiles are in an image.
139.  */
140. uint32
     ^
141. TIFFNumberOfTiles(TIFF* tif)
142. {

libtiff/tif_tile.c:140:1: Parameter `tif->tif_dir.td_imagedepth`
            138.  * Compute how many tiles are in an image.
            139.  */
            140. uint32
                 ^
            141. TIFFNumberOfTiles(TIFF* tif)
            142. {

libtiff/tif_tile.c:140:1: <RHS trace>
138.  * Compute how many tiles are in an image.
139.  */
140. uint32
     ^
141. TIFFNumberOfTiles(TIFF* tif)
142. {

libtiff/tif_tile.c:140:1: Parameter `tif->tif_dir.td_imagedepth`
            138.  * Compute how many tiles are in an image.
            139.  */
            140. uint32
                 ^
            141. TIFFNumberOfTiles(TIFF* tif)
            142. {

libtiff/tif_tile.c:159:6: Binary operation: ([min(1, out->tif_dir.td_imagedepth), 4294967294] + [0, 4294967294-min(1, out->tif_dir.td_imagedepth)]):unsigned32 by call to `writeSingleSection` 
            157. 	    TIFFhowmany_32(td->td_imagelength, dy),
            158. 	    "TIFFNumberOfTiles"),
            159. 	    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
                      ^
            160. 	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
            161. 		ntiles = multiply_32(tif, ntiles, td->td_samplesperpixel,

uint32
TIFFNumberOfTiles(TIFF* tif)
{
	TIFFDirectory *td = &tif->tif_dir;
	uint32 dx = td->td_tilewidth;
	uint32 dy = td->td_tilelength;
	uint32 dz = td->td_tiledepth;
	uint32 ntiles;
	if (dx == (uint32) -1)
		dx = td->td_imagewidth;
	if (dy == (uint32) -1)
		dy = td->td_imagelength;
	if (dz == (uint32) -1)
		dz = td->td_imagedepth;
	ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
	    multiply_32(tif, multiply_32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
	    TIFFhowmany_32(td->td_imagelength, dy),
	    "TIFFNumberOfTiles"),
	    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
		ntiles = multiply_32(tif, ntiles, td->td_samplesperpixel,
		    "TIFFNumberOfTiles");
	return (ntiles);
}
['static int\nwriteImageSections(TIFF *in, TIFF *out, struct image_data *image,\n\t\t   struct pagedef *page, struct pageseg *sections,\n\t\t   struct dump_opts * dump, unsigned char *src_buff,\n                   unsigned char **sect_buff_ptr)\n  {\n  double  hres, vres;\n  uint32  i, k, width, length, sectsize;\n  unsigned char *sect_buff = *sect_buff_ptr;\n  hres = page->hres;\n  vres = page->vres;\n  k = page->cols * page->rows;\n  if ((k < 1) || (k > MAX_SECTIONS))\n   {\n   TIFFError("writeImageSections",\n\t     "%d Rows and Columns exceed maximum sections\\nIncrease resolution or reduce sections", k);\n   return (-1);\n   }\n  for (i = 0; i < k; i++)\n    {\n    width  = sections[i].x2 - sections[i].x1 + 1;\n    length = sections[i].y2 - sections[i].y1 + 1;\n    sectsize = (uint32)\n\t    ceil((width * image->bps + 7) / (double)8) * image->spp * length;\n    if (createImageSection(sectsize, sect_buff_ptr))\n      {\n      TIFFError("writeImageSections", "Unable to allocate section buffer");\n      exit (-1);\n      }\n    sect_buff = *sect_buff_ptr;\n    if (extractImageSection (image, &sections[i], src_buff, sect_buff))\n      {\n      TIFFError("writeImageSections", "Unable to extract image sections");\n      exit (-1);\n      }\n    if (writeSingleSection(in, out, image, dump, width, length, hres, vres, sect_buff))\n      {\n      TIFFError("writeImageSections", "Unable to write image section");\n      exit (-1);\n      }\n    }\n  return (0);\n  }', 'static int\nwriteSingleSection(TIFF *in, TIFF *out, struct image_data *image,\n                   struct dump_opts *dump, uint32 width, uint32 length,\n                   double hres, double vres,\n                   unsigned char *sect_buff)\n  {\n  uint16 bps, spp;\n  uint16 input_compression, input_photometric;\n  uint16 input_jpeg_colormode, input_planar;\n  struct cpTag* p;\n  TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &input_photometric);\n  TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &spp);\n  TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &bps);\n  TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);\n  TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);\n  CopyField(TIFFTAG_BITSPERSAMPLE, bps);\n  CopyField(TIFFTAG_SAMPLESPERPIXEL, spp);\n  TIFFGetField(in, TIFFTAG_COMPRESSION, &input_compression);\n  if (compression != (uint16)-1)\n    TIFFSetField(out, TIFFTAG_COMPRESSION, compression);\n  else\n    {\n    if (input_compression == COMPRESSION_OJPEG)\n      {\n      TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n      compression = COMPRESSION_JPEG;\n      }\n    else\n      CopyField(TIFFTAG_COMPRESSION, compression);\n    }\n  TIFFGetField(in, TIFFTAG_JPEGCOLORMODE, &input_jpeg_colormode);\n#ifdef DEBUG2\n  TIFFError("writeSingleSection", "Input compression: %s",\n\t    (input_compression == COMPRESSION_OJPEG) ? "Old Jpeg" :\n\t    ((input_compression == COMPRESSION_JPEG) ?  "New Jpeg" : "Non Jpeg"));\n#endif\n  if (compression == COMPRESSION_JPEG)\n    {\n    if ((input_photometric == PHOTOMETRIC_PALETTE) ||\n        (input_photometric == PHOTOMETRIC_MASK))\n      {\n      TIFFError ("writeSingleSection",\n                 "JPEG compression cannot be used with %s image data",\n\t\t (input_photometric == PHOTOMETRIC_PALETTE) ?\n                 "palette" : "mask");\n      return (-1);\n      }\n    if (input_photometric == PHOTOMETRIC_RGB)\n      {\n      if (jpegcolormode == JPEGCOLORMODE_RGB)\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n      else\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);\n      }\n    else\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric);\n    }\n  else\n    {\n    if (compression == COMPRESSION_SGILOG || compression == COMPRESSION_SGILOG24)\n      TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\tPHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n    else\n      TIFFSetField(out, TIFFTAG_PHOTOMETRIC, image->photometric);\n    }\n  if (((input_photometric == PHOTOMETRIC_LOGL) ||\n       (input_photometric ==  PHOTOMETRIC_LOGLUV)) &&\n      ((compression != COMPRESSION_SGILOG) &&\n       (compression != COMPRESSION_SGILOG24)))\n    {\n    TIFFError("writeCroppedImage",\n              "LogL and LogLuv source data require SGI_LOG or SGI_LOG24 compression");\n    return (-1);\n    }\n  if (fillorder != 0)\n    TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);\n  else\n    CopyTag(TIFFTAG_FILLORDER, 1, TIFF_SHORT);\n  TIFFSetField(out, TIFFTAG_ORIENTATION, image->orientation);\n  if (outtiled == -1)\n    outtiled = TIFFIsTiled(in);\n  if (outtiled) {\n    if (tilewidth == (uint32) 0)\n      TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth);\n    if (tilelength == (uint32) 0)\n      TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength);\n    if (tilewidth == 0 || tilelength == 0)\n      TIFFDefaultTileSize(out, &tilewidth, &tilelength);\n    TIFFDefaultTileSize(out, &tilewidth, &tilelength);\n    TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);\n    TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);\n    } else {\n\tif (rowsperstrip == (uint32) 0)\n          {\n\t  if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip))\n\t    rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);\n          if (compression != COMPRESSION_JPEG)\n            {\n  \t    if (rowsperstrip > length)\n\t      rowsperstrip = length;\n\t    }\n\t  }\n\telse\n          if (rowsperstrip == (uint32) -1)\n\t    rowsperstrip = length;\n\tTIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);\n\t}\n  TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar);\n  if (config != (uint16) -1)\n    TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);\n  else\n    CopyField(TIFFTAG_PLANARCONFIG, config);\n  if (spp <= 4)\n    CopyTag(TIFFTAG_TRANSFERFUNCTION, 4, TIFF_SHORT);\n  CopyTag(TIFFTAG_COLORMAP, 4, TIFF_SHORT);\n  switch (compression) {\n    case COMPRESSION_JPEG:\n         if (((bps % 8) == 0) || ((bps % 12) == 0))\n\t   {\n           TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);\n\t   TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n           }\n         else\n           {\n\t   TIFFError("writeCroppedImage",\n                     "JPEG compression requires 8 or 12 bits per sample");\n           return (-1);\n           }\n\t break;\n   case COMPRESSION_LZW:\n   case COMPRESSION_ADOBE_DEFLATE:\n   case COMPRESSION_DEFLATE:\n\tif (predictor != (uint16)-1)\n          TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);\n\telse\n\t  CopyField(TIFFTAG_PREDICTOR, predictor);\n\tbreak;\n   case COMPRESSION_CCITTFAX3:\n   case COMPRESSION_CCITTFAX4:\n\tif (compression == COMPRESSION_CCITTFAX3) {\n          if (g3opts != (uint32) -1)\n\t    TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);\n\t  else\n\t    CopyField(TIFFTAG_GROUP3OPTIONS, g3opts);\n\t} else\n\t    CopyTag(TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_BADFAXLINES, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_CLEANFAXDATA, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);\n\tbreak;\n   }\n   { uint32 len32;\n     void** data;\n     if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data))\n       TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data);\n   }\n   { uint16 ninks;\n     const char* inknames;\n     if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) {\n       TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks);\n       if (TIFFGetField(in, TIFFTAG_INKNAMES, &inknames)) {\n\t int inknameslen = strlen(inknames) + 1;\n\t const char* cp = inknames;\n\t while (ninks > 1) {\n\t   cp = strchr(cp, \'\\0\');\n\t   if (cp) {\n\t     cp++;\n\t     inknameslen += (strlen(cp) + 1);\n\t   }\n\t   ninks--;\n         }\n\t TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames);\n       }\n     }\n   }\n   {\n   unsigned short pg0, pg1;\n   if (TIFFGetField(in, TIFFTAG_PAGENUMBER, &pg0, &pg1)) {\n     if (pageNum < 0)\n\tTIFFSetField(out, TIFFTAG_PAGENUMBER, pg0, pg1);\n     else\n\tTIFFSetField(out, TIFFTAG_PAGENUMBER, pageNum++, 0);\n     }\n   }\n  for (p = tags; p < &tags[NTAGS]; p++)\n\t\tCopyTag(p->tag, p->count, p->type);\n  TIFFSetField(out, TIFFTAG_XRESOLUTION, (float)hres);\n  TIFFSetField(out, TIFFTAG_YRESOLUTION, (float)vres);\n  if (outtiled)\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      writeBufferToContigTiles (out, sect_buff, length, width, spp, dump);\n    else\n      writeBufferToSeparateTiles (out, sect_buff, length, width, spp, dump);\n    }\n  else\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      writeBufferToContigStrips (out, sect_buff, length);\n    else\n      writeBufferToSeparateStrips(out, sect_buff, length, width, spp, dump);\n    }\n  if (!TIFFWriteDirectory(out))\n    {\n    TIFFClose(out);\n    return (-1);\n    }\n  return (0);\n  }', 'static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength)\n  {\n  uint32 row, nrows, rowsperstrip;\n  tstrip_t strip = 0;\n  tsize_t stripsize;\n  TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);\n  for (row = 0; row < imagelength; row += rowsperstrip)\n    {\n    nrows = (row + rowsperstrip > imagelength) ?\n\t     imagelength - row : rowsperstrip;\n    stripsize = TIFFVStripSize(out, nrows);\n    if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0)\n      {\n      TIFFError(TIFFFileName(out), "Error, can\'t write strip %u", strip - 1);\n      return 1;\n      }\n    buf += stripsize;\n    }\n  return 0;\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\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\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\tif( td->td_stripbytecount[strip] > 0 )\n        {\n            tif->tif_curoff = 0;\n        }\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\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 (0);\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\nTIFFWriteCheck(TIFF* tif, int tiles, const char* module)\n{\n\tif (tif->tif_mode == O_RDONLY) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "File not open for writing");\n\t\treturn (0);\n\t}\n\tif (tiles ^ isTiled(tif)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, tiles ?\n\t\t    "Can not write tiles to a stripped image" :\n\t\t    "Can not write scanlines to a tiled image");\n\t\treturn (0);\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t    "Must set \\"ImageWidth\\" before writing data");\n\t\treturn (0);\n\t}\n\tif (tif->tif_dir.td_samplesperpixel == 1) {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG))\n                    tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;\n\t} else {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "Must set \\"PlanarConfiguration\\" before writing data");\n\t\t\treturn (0);\n\t\t}\n\t}\n\tif (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {\n\t\ttif->tif_dir.td_nstrips = 0;\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",\n\t\t    isTiled(tif) ? "tile" : "strip");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif))\n\t{\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (tif->tif_tilesize == 0)\n\t\t\treturn (0);\n\t}\n\telse\n\t\ttif->tif_tilesize = (tmsize_t)(-1);\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (tif->tif_scanlinesize == 0)\n\t\treturn (0);\n\ttif->tif_flags |= TIFF_BEENWRITING;\n\treturn (1);\n}', 'int\nTIFFSetupStrips(TIFF* tif)\n{\n\tTIFFDirectory* td = &tif->tif_dir;\n\tif (isTiled(tif))\n\t\ttd->td_stripsperimage =\n\t\t    isUnspecified(tif, FIELD_TILEDIMENSIONS) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfTiles(tif);\n\telse\n\t\ttd->td_stripsperimage =\n\t\t    isUnspecified(tif, FIELD_ROWSPERSTRIP) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfStrips(tif);\n\ttd->td_nstrips = td->td_stripsperimage;\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttd->td_stripsperimage /= td->td_samplesperpixel;\n\ttd->td_stripoffset = (uint64 *)\n\t    _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\ttd->td_stripbytecount = (uint64 *)\n\t    _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\tif (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)\n\t\treturn (0);\n\t_TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64));\n\t_TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64));\n\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\tTIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);\n\treturn (1);\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t    multiply_32(tif, multiply_32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t    TIFFhowmany_32(td->td_imagelength, dy),\n\t    "TIFFNumberOfTiles"),\n\t    TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = multiply_32(tif, ntiles, td->td_samplesperpixel,\n\t\t    "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']