tools/tiffcrop.c:5775: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `writeCroppedImage`.

tools/tiffcrop.c:5756:1: Parameter `(*out)->tif_dir.td_rowsperstrip`
5754.   } /* end extractImageSection */
5755. 
5756. static int 
      ^
5757. writeSelections(TIFF *in, TIFF **out, struct crop_mask *crop, 
5758.                 struct image_data *image, struct dump_opts *dump,

tools/tiffcrop.c:5772:14: Call
5770.          autoindex = 0;
5771.          crop_buff = seg_buffs[0].buffer;
5772.          if (update_output_file (out, mp, autoindex, filename, page))
                   ^
5773.            return (1);
5774.          page_count = total_pages;

tools/tiffcrop.c:1794:1: Parameter `(*tiffout)->tif_dir.td_rowsperstrip`
  1792.  * so TIFFTAG PAGENUM will be correct in image.
  1793.  */
  1794. static int 
        ^
  1795. update_output_file (TIFF **tiffout, char *mode, int autoindex,
  1796.                     char *outname, unsigned int *page)

tools/tiffcrop.c:5775:14: Call
5773.            return (1);
5774.          page_count = total_pages;
5775.          if (writeCroppedImage(in, *out, image, dump,
                   ^
5776.                                crop->combined_width, 
5777.                                crop->combined_length,

tools/tiffcrop.c:6545:1: Parameter `out->tif_dir.td_rowsperstrip`
  6543. 
  6544. /* The code in this function is heavily indebted to code from tiffcp. */
  6545. static int  
        ^
  6546. writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, 
  6547.                   struct dump_opts *dump, uint32 width, uint32 length, 

tools/tiffcrop.c:6727:7: Call
  6725.     if (config == PLANARCONFIG_CONTIG)
  6726.       {
  6727.       writeBufferToContigTiles (out, crop_buff, length, width, spp);
              ^
  6728.       }
  6729.     else

tools/tiffcrop.c:981:1: Parameter `out->tif_dir.td_rowsperstrip`
    979. }
    980. 
    981. static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,
         ^
    982.                                      uint32 imagewidth, tsample_t spp)
    983. {

tools/tiffcrop.c:1015:8: Call
    1013. 				cpStripToTile(obuf, bufp + colb, nrow, tilew,
    1014. 				    0, iskew);
    1015. 			if (TIFFWriteTile(out, obuf, col, row, 0, 0) < 0) {
                 ^
    1016. 				TIFFError(TIFFFileName(out),
    1017. 					  "Error, can't write tile at %lu %lu",

libtiff/tif_write.c:312:1: Parameter `tif->tif_dir.td_rowsperstrip`
      310.  * tile is selected by the (x,y,z,s) coordinates.
      311.  */
      312. tmsize_t
           ^
      313. TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)
      314. {

libtiff/tif_write.c:323:10: Call
      321. 	 *     after the output buffer is setup in TIFFWriteBufferSetup.
      322. 	 */
      323. 	return (TIFFWriteEncodedTile(tif,
                    ^
      324. 	    TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));
      325. }

libtiff/tif_write.c:339:1: Parameter `tif->tif_dir.td_rowsperstrip`
        337.  *     the image on each write (as TIFFWriteScanline does).
        338.  */
        339. tmsize_t
             ^
        340. TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
        341. {

libtiff/tif_write.c:346:7: Call
        344. 	uint16 sample;
        345. 
        346. 	if (!WRITECHECKTILES(tif, module))
                   ^
        347. 		return ((tmsize_t)(-1));
        348. 	td = &tif->tif_dir;

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

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

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

libtiff/tif_write.c:460:29: Call
            458. 		td->td_stripsperimage =
            459. 		    isUnspecified(tif, FIELD_ROWSPERSTRIP) ?
            460. 			td->td_samplesperpixel : TIFFNumberOfStrips(tif);
                                             ^
            461. 	td->td_nstrips = td->td_stripsperimage;
            462. 	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)

libtiff/tif_strip.c:86:1: <LHS trace>
84.  * Compute how many strips are in an image.
85.  */
86. uint32
    ^
87. TIFFNumberOfStrips(TIFF* tif)
88. {

libtiff/tif_strip.c:86:1: Parameter `tif->tif_dir.td_rowsperstrip`
              84.  * Compute how many strips are in an image.
              85.  */
              86. uint32
                  ^
              87. TIFFNumberOfStrips(TIFF* tif)
              88. {

libtiff/tif_strip.c:92:13: Binary operation: ([0, +oo] - 1):unsigned32 by call to `writeCroppedImage` 
              90. 	uint32 nstrips;
              91. 
              92. 	nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
                              ^
              93. 	     TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
              94. 	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)

uint32
TIFFNumberOfStrips(TIFF* tif)
{
	TIFFDirectory *td = &tif->tif_dir;
	uint32 nstrips;
	nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
	     TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
		nstrips = multiply_32(tif, nstrips, (uint32)td->td_samplesperpixel,
		    "TIFFNumberOfStrips");
	return (nstrips);
}
['static int\nwriteSelections(TIFF *in, TIFF **out, struct crop_mask *crop,\n                struct image_data *image, struct dump_opts *dump,\n                struct buffinfo seg_buffs[], char *mp, char *filename,\n                unsigned int *page, unsigned int total_pages)\n  {\n  int i, page_count;\n  int autoindex = 0;\n  unsigned char *crop_buff = NULL;\n  switch (crop->exp_mode)\n    {\n    case ONE_FILE_COMPOSITE:\n         autoindex = 0;\n         crop_buff = seg_buffs[0].buffer;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         page_count = total_pages;\n         if (writeCroppedImage(in, *out, image, dump,\n                               crop->combined_width,\n                               crop->combined_length,\n                               crop_buff, *page, total_pages))\n            {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n\t break;\n    case ONE_FILE_SEPARATED:\n         autoindex = 0;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         page_count = crop->selections * total_pages;\n         for (i = 0; i < crop->selections; i++)\n           {\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n\t   }\n         break;\n    case FILE_PER_IMAGE_COMPOSITE:\n         autoindex = 1;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         crop_buff = seg_buffs[0].buffer;\n         if (writeCroppedImage(in, *out, image, dump,\n                               crop->combined_width,\n                               crop->combined_length,\n                               crop_buff, *page, total_pages))\n           {\n           TIFFError("writeRegions", "Unable to write new image");\n           return (-1);\n           }\n         break;\n    case FILE_PER_IMAGE_SEPARATED:\n         autoindex = 1;\n         page_count = crop->selections;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         for (i = 0; i < crop->selections; i++)\n           {\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n           }\n         break;\n    case FILE_PER_SELECTION:\n         autoindex = 1;\n\t page_count = 1;\n         for (i = 0; i < crop->selections; i++)\n           {\n           if (update_output_file (out, mp, autoindex, filename, page))\n             return (1);\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n           }\n\t break;\n    default: return (1);\n    }\n  return (0);\n  }', 'static int\nupdate_output_file (TIFF **tiffout, char *mode, int autoindex,\n                    char *outname, unsigned int *page)\n  {\n  static int findex = 0;\n  char  *sep;\n  char   filenum[16];\n  char   export_ext[16];\n  char   exportname[PATH_MAX];\n  strcpy (export_ext, ".tiff");\n  if (autoindex && (*tiffout != NULL))\n    {\n    TIFFClose (*tiffout);\n    *tiffout = NULL;\n    }\n  strncpy (exportname, outname, PATH_MAX - 15);\n  if (*tiffout == NULL)\n    {\n    if (autoindex)\n      {\n      findex++;\n      if ((sep = strstr(exportname, ".tif")) || (sep = strstr(exportname, ".TIF")))\n        {\n        strncpy (export_ext, sep, 5);\n        *sep = \'\\0\';\n        }\n      else\n        strncpy (export_ext, ".tiff", 5);\n      export_ext[5] = \'\\0\';\n      sprintf (filenum, "-%03d%s", findex, export_ext);\n      filenum[15] = \'\\0\';\n      strncat (exportname, filenum, 14);\n      }\n    *tiffout = TIFFOpen(exportname, mode);\n    if (*tiffout == NULL)\n      {\n      TIFFError("update_output_file", "Unable to open output file %s\\n", exportname);\n      return (1);\n      }\n    *page = 0;\n    return (0);\n    }\n  else\n    (*page)++;\n  return (0);\n  }', "static int\nwriteCroppedImage(TIFF *in, TIFF *out, struct image_data *image,\n                  struct dump_opts *dump, uint32 width, uint32 length,\n                  unsigned char *crop_buff, int pagenum, int total_pages)\n  {\n  uint16 bps, spp;\n  struct cpTag* p;\n  TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);\n  TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);\n  CopyField(TIFFTAG_BITSPERSAMPLE, bps);\n  CopyField(TIFFTAG_SAMPLESPERPIXEL, spp);\n  if (compression != (uint16)-1)\n    TIFFSetField(out, TIFFTAG_COMPRESSION, compression);\n  else\n    CopyField(TIFFTAG_COMPRESSION, compression);\n  if (compression == COMPRESSION_JPEG) {\n    uint16 input_compression, input_photometric;\n    if (TIFFGetField(in, TIFFTAG_COMPRESSION, &input_compression)\n        && input_compression == COMPRESSION_JPEG) {\n          TIFFSetField(in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n        }\n    if (TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &input_photometric)) {\n\tif(input_photometric == PHOTOMETRIC_RGB) {\n\t   if (jpegcolormode == JPEGCOLORMODE_RGB)\n\t     TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t   else\n\t     TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);\n\t   } else\n\t      TIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric);\n\t}\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 (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) -1)\n      TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth);\n    if (tilelength == (uint32) -1)\n      TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength);\n    if (tilewidth > width)\n      tilewidth = width;\n    if (tilelength > length)\n      tilelength = length;\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            {\n\t    rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);\n\t    }\n\t  if (rowsperstrip > length)\n\t    rowsperstrip = length;\n\t  }\n\telse\n          if (rowsperstrip == (uint32) -1)\n\t    rowsperstrip = length;\n\tTIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);\n\t}\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         TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);\n\t TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);\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     TIFFSetField(out, TIFFTAG_PAGENUMBER, pagenum, total_pages);\n     }\n   }\n  for (p = tags; p < &tags[NTAGS]; p++)\n\t\tCopyTag(p->tag, p->count, p->type);\n  if (outtiled)\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      {\n      writeBufferToContigTiles (out, crop_buff, length, width, spp);\n      }\n    else\n      writeBufferToSeparateTiles (out, crop_buff, length, width, spp, dump);\n    }\n  else\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      {\n      writeBufferToContigStrips (out, crop_buff, length, width, spp);\n      }\n    else\n      {\n      writeBufferToSeparateStrips(out, crop_buff, length, width, spp, dump);\n      }\n    }\n  if (!TIFFWriteDirectory(out))\n    {\n    TIFFClose(out);\n    return (-1);\n    }\n  return (0);\n  }", 'static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,\n                                     uint32 imagewidth, tsample_t spp)\n{\n\tuint32 imagew = TIFFScanlineSize(out);\n\tuint32 tilew  = TIFFTileRowSize(out);\n\tint iskew = imagew - tilew;\n\ttdata_t obuf = _TIFFmalloc(TIFFTileSize(out));\n\tuint8* bufp = (uint8*) buf;\n\tuint32 tl, tw;\n\tuint32 row;\n\t(void) spp;\n\tif (obuf == NULL)\n\t\treturn 0;\n\t(void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);\n\t(void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);\n\tfor (row = 0; row < imagelength; row += tilelength) {\n\t\tuint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;\n\t\tuint32 colb = 0;\n\t\tuint32 col;\n\t\tfor (col = 0; col < imagewidth; col += tw) {\n\t\t\tif (colb + tilew > imagew) {\n\t\t\t\tuint32 width = imagew - colb;\n\t\t\t\tint oskew = tilew - width;\n\t\t\t\tcpStripToTile(obuf, bufp + colb, nrow, width,\n\t\t\t\t    oskew, oskew + iskew);\n\t\t\t} else\n\t\t\t\tcpStripToTile(obuf, bufp + colb, nrow, tilew,\n\t\t\t\t    0, iskew);\n\t\t\tif (TIFFWriteTile(out, obuf, col, row, 0, 0) < 0) {\n\t\t\t\tTIFFError(TIFFFileName(out),\n\t\t\t\t\t  "Error, can\'t write tile at %lu %lu",\n\t\t\t\t\t  (unsigned long) col,\n\t\t\t\t\t  (unsigned long) row);\n\t\t\t\t_TIFFfree(obuf);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tcolb += tilew;\n\t\t}\n\t\tbufp += nrow * imagew;\n\t}\n\t_TIFFfree(obuf);\n\treturn 1;\n}', 'tmsize_t\nTIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFWriteEncodedTile(tif,\n\t    TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedTile";\n\tTIFFDirectory *td;\n\tuint16 sample;\n\tif (!WRITECHECKTILES(tif, module))\n\t\treturn ((tmsize_t)(-1));\n\ttd = &tif->tif_dir;\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu",\n\t\t    (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t)(-1));\n        tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curtile = tile;\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\tif( td->td_stripbytecount[tile] > 0 )\n        {\n            tif->tif_curoff = 0;\n        }\n\ttif->tif_row = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength))\n\t\t* td->td_tilelength;\n\ttif->tif_col = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth))\n\t\t* td->td_tilewidth;\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_flags &= ~TIFF_POSTENCODE;\n\tsample = (uint16)(tile/td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t)(-1));\n\tif ( cc < 1 || cc > tif->tif_tilesize)\n\t\tcc = tif->tif_tilesize;\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodetile)(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((uint8*)tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,\n\t    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\ttif->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\nTIFFNumberOfStrips(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 nstrips;\n\tnstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :\n\t     TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tnstrips = multiply_32(tif, nstrips, (uint32)td->td_samplesperpixel,\n\t\t    "TIFFNumberOfStrips");\n\treturn (nstrips);\n}']