tools/tiffcrop.c:4924: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32.

tools/tiffcrop.c:4713:1: <LHS trace>
4711. 
4712. 
4713. static int
      ^
4714. computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image,
4715.                            struct pagedef *page, struct pageseg *sections,

tools/tiffcrop.c:4713:1: Parameter `crop->combined_length`
4711. 
4712. 
4713. static int
      ^
4714. computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image,
4715.                            struct pagedef *page, struct pageseg *sections,

tools/tiffcrop.c:4752:5: Assignment
4750.     iwidth = image->width;
4751.   if (crop->combined_length > 0)
4752.     ilength = crop->combined_length;
          ^
4753.   else
4754.     ilength = image->length;

tools/tiffcrop.c:4924:7: Binary operation: ([0, +oo] - 1):unsigned32
4922.     y2 = (uint32)(olength * (i +  1) - 1);
4923.     if (y2 >= ilength)
4924.       y2 = ilength - 1;
            ^
4925.     for (j = 0; j < ocols; j++, k++)
4926.       {

static int
computeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image,
                           struct pagedef *page, struct pageseg *sections,
                           struct dump_opts* dump)
  {
  double scale;
  uint32 iwidth, ilength;
  uint32 owidth, olength;
  uint32 pwidth, plength;
  uint32 orows, ocols;
  uint32 hmargin, vmargin;
  uint32 x1, x2, y1, y2, line_bytes;
  unsigned int orientation;
  uint32 i, j, k;
  scale = 1.0;
  if (page->res_unit == RESUNIT_NONE)
    page->res_unit = image->res_unit;
  switch (image->res_unit) {
    case RESUNIT_CENTIMETER:
         if (page->res_unit == RESUNIT_INCH)
	   scale = 1.0/2.54;
	 break;
    case RESUNIT_INCH:
	 if (page->res_unit == RESUNIT_CENTIMETER)
	     scale = 2.54;
	 break;
    case RESUNIT_NONE:
    default:
    break;
    }
  if (crop->combined_width > 0)
    iwidth = crop->combined_width;
  else
    iwidth = image->width;
  if (crop->combined_length > 0)
    ilength = crop->combined_length;
  else
    ilength = image->length;
  if (page->hres <= 1.0)
    page->hres = image->xres;
  if (page->vres <= 1.0)
    page->vres = image->yres;
  if ((page->hres < 1.0) || (page->vres < 1.0))
    {
    TIFFError("computeOutputPixelOffsets",
    "Invalid horizontal or vertical resolution specified or read from input image");
    return (1);
    }
  if (page->width <= 0)
    pwidth = iwidth;
  else
    pwidth = page->width;
  if (page->length <= 0)
    plength = ilength;
  else
    plength = page->length;
  if (dump->debug)
    {
    TIFFError("", "Page size: %s, Vres: %3.2f, Hres: %3.2f, "
                   "Hmargin: %3.2f, Vmargin: %3.2f\n",
	     page->name, page->vres, page->hres,
             page->hmargin, page->vmargin);
    TIFFError("", "Res_unit: %d, Scale: %3.2f, Page width: %d, length: %d\n",
           page->res_unit, scale, pwidth, plength);
    }
  if (page->mode & PAGE_MODE_MARGINS)
    {
    if (page->res_unit == RESUNIT_INCH || page->res_unit == RESUNIT_CENTIMETER)
      {
      hmargin = (uint32)(page->hmargin * scale * page->hres * ((image->bps + 7)/ 8));
      vmargin = (uint32)(page->vmargin * scale * page->vres * ((image->bps + 7)/ 8));
      }
    else
      {
      hmargin = (uint32)(page->hmargin * scale * ((image->bps + 7)/ 8));
      vmargin = (uint32)(page->vmargin * scale * ((image->bps + 7)/ 8));
      }
    if ((hmargin * 2.0) > (pwidth * page->hres))
      {
      TIFFError("computeOutputPixelOffsets",
                "Combined left and right margins exceed page width");
      hmargin = (uint32) 0;
      return (-1);
      }
    if ((vmargin * 2.0) > (plength * page->vres))
      {
      TIFFError("computeOutputPixelOffsets",
                "Combined top and bottom margins exceed page length");
      vmargin = (uint32) 0;
      return (-1);
      }
    }
  else
    {
    hmargin = 0;
    vmargin = 0;
    }
  if (page->mode & PAGE_MODE_ROWSCOLS )
    {
    if (page->mode & PAGE_MODE_MARGINS)
      TIFFError("computeOutputPixelOffsets",
      "Output margins cannot be specified with rows and columns");
    owidth  = TIFFhowmany(iwidth, page->cols);
    olength = TIFFhowmany(ilength, page->rows);
    }
  else
    {
    if (page->mode & PAGE_MODE_PAPERSIZE )
      {
      owidth  = (uint32)((pwidth * page->hres) - (hmargin * 2));
      olength = (uint32)((plength * page->vres) - (vmargin * 2));
      }
    else
      {
      owidth = (uint32)(iwidth - (hmargin * 2 * page->hres));
      olength = (uint32)(ilength - (vmargin * 2 * page->vres));
      }
    }
  if (owidth > iwidth)
    owidth = iwidth;
  if (olength > ilength)
    olength = ilength;
  switch (page->orient)
    {
    case ORIENTATION_NONE:
    case ORIENTATION_PORTRAIT:
         ocols = TIFFhowmany(iwidth, owidth);
         orows = TIFFhowmany(ilength, olength);
         orientation = ORIENTATION_PORTRAIT;
         break;
    case ORIENTATION_LANDSCAPE:
         ocols = TIFFhowmany(iwidth, olength);
         orows = TIFFhowmany(ilength, owidth);
         x1 = olength;
         olength = owidth;
         owidth = x1;
         orientation = ORIENTATION_LANDSCAPE;
         break;
    case ORIENTATION_AUTO:
    default:
         x1 = TIFFhowmany(iwidth, owidth);
         x2 = TIFFhowmany(ilength, olength);
         y1 = TIFFhowmany(iwidth, olength);
         y2 = TIFFhowmany(ilength, owidth);
         if ( (x1 * x2) < (y1 * y2))
           {
           ocols = x1;
           orows = x2;
           orientation = ORIENTATION_PORTRAIT;
	   }
         else
           {
           ocols = y1;
           orows = y2;
           x1 = olength;
           olength = owidth;
           owidth = x1;
           orientation = ORIENTATION_LANDSCAPE;
           }
    }
  if (ocols < 1)
    ocols = 1;
  if (orows < 1)
    orows = 1;
  if (page->rows < 1)
    page->rows = orows;
  if (page->cols < 1)
    page->cols = ocols;
  line_bytes = TIFFhowmany8(owidth * image->bps) * image->spp;
  if ((page->rows * page->cols) > MAX_SECTIONS)
   {
   TIFFError("computeOutputPixelOffsets",
	     "Rows and Columns exceed maximum sections\nIncrease resolution or reduce sections");
   return (-1);
   }
  for (k = 0, i = 0 && k <= MAX_SECTIONS; i < orows; i++)
    {
    y1 = (uint32)(olength * i);
    y2 = (uint32)(olength * (i +  1) - 1);
    if (y2 >= ilength)
      y2 = ilength - 1;
    for (j = 0; j < ocols; j++, k++)
      {
      x1 = (uint32)(owidth * j);
      x2 = (uint32)(owidth * (j + 1) - 1);
      if (x2 >= iwidth)
        x2 = iwidth - 1;
      sections[k].x1 = x1;
      sections[k].x2 = x2;
      sections[k].y1 = y1;
      sections[k].y2 = y2;
      sections[k].buffsize = line_bytes * olength;
      sections[k].position = k + 1;
      sections[k].total = orows * ocols;
      }
    }
  return (0);
  }
['static int\ncomputeOutputPixelOffsets (struct crop_mask *crop, struct image_data *image,\n                           struct pagedef *page, struct pageseg *sections,\n                           struct dump_opts* dump)\n  {\n  double scale;\n  uint32 iwidth, ilength;\n  uint32 owidth, olength;\n  uint32 pwidth, plength;\n  uint32 orows, ocols;\n  uint32 hmargin, vmargin;\n  uint32 x1, x2, y1, y2, line_bytes;\n  unsigned int orientation;\n  uint32 i, j, k;\n  scale = 1.0;\n  if (page->res_unit == RESUNIT_NONE)\n    page->res_unit = image->res_unit;\n  switch (image->res_unit) {\n    case RESUNIT_CENTIMETER:\n         if (page->res_unit == RESUNIT_INCH)\n\t   scale = 1.0/2.54;\n\t break;\n    case RESUNIT_INCH:\n\t if (page->res_unit == RESUNIT_CENTIMETER)\n\t     scale = 2.54;\n\t break;\n    case RESUNIT_NONE:\n    default:\n    break;\n    }\n  if (crop->combined_width > 0)\n    iwidth = crop->combined_width;\n  else\n    iwidth = image->width;\n  if (crop->combined_length > 0)\n    ilength = crop->combined_length;\n  else\n    ilength = image->length;\n  if (page->hres <= 1.0)\n    page->hres = image->xres;\n  if (page->vres <= 1.0)\n    page->vres = image->yres;\n  if ((page->hres < 1.0) || (page->vres < 1.0))\n    {\n    TIFFError("computeOutputPixelOffsets",\n    "Invalid horizontal or vertical resolution specified or read from input image");\n    return (1);\n    }\n  if (page->width <= 0)\n    pwidth = iwidth;\n  else\n    pwidth = page->width;\n  if (page->length <= 0)\n    plength = ilength;\n  else\n    plength = page->length;\n  if (dump->debug)\n    {\n    TIFFError("", "Page size: %s, Vres: %3.2f, Hres: %3.2f, "\n                   "Hmargin: %3.2f, Vmargin: %3.2f\\n",\n\t     page->name, page->vres, page->hres,\n             page->hmargin, page->vmargin);\n    TIFFError("", "Res_unit: %d, Scale: %3.2f, Page width: %d, length: %d\\n",\n           page->res_unit, scale, pwidth, plength);\n    }\n  if (page->mode & PAGE_MODE_MARGINS)\n    {\n    if (page->res_unit == RESUNIT_INCH || page->res_unit == RESUNIT_CENTIMETER)\n      {\n      hmargin = (uint32)(page->hmargin * scale * page->hres * ((image->bps + 7)/ 8));\n      vmargin = (uint32)(page->vmargin * scale * page->vres * ((image->bps + 7)/ 8));\n      }\n    else\n      {\n      hmargin = (uint32)(page->hmargin * scale * ((image->bps + 7)/ 8));\n      vmargin = (uint32)(page->vmargin * scale * ((image->bps + 7)/ 8));\n      }\n    if ((hmargin * 2.0) > (pwidth * page->hres))\n      {\n      TIFFError("computeOutputPixelOffsets",\n                "Combined left and right margins exceed page width");\n      hmargin = (uint32) 0;\n      return (-1);\n      }\n    if ((vmargin * 2.0) > (plength * page->vres))\n      {\n      TIFFError("computeOutputPixelOffsets",\n                "Combined top and bottom margins exceed page length");\n      vmargin = (uint32) 0;\n      return (-1);\n      }\n    }\n  else\n    {\n    hmargin = 0;\n    vmargin = 0;\n    }\n  if (page->mode & PAGE_MODE_ROWSCOLS )\n    {\n    if (page->mode & PAGE_MODE_MARGINS)\n      TIFFError("computeOutputPixelOffsets",\n      "Output margins cannot be specified with rows and columns");\n    owidth  = TIFFhowmany(iwidth, page->cols);\n    olength = TIFFhowmany(ilength, page->rows);\n    }\n  else\n    {\n    if (page->mode & PAGE_MODE_PAPERSIZE )\n      {\n      owidth  = (uint32)((pwidth * page->hres) - (hmargin * 2));\n      olength = (uint32)((plength * page->vres) - (vmargin * 2));\n      }\n    else\n      {\n      owidth = (uint32)(iwidth - (hmargin * 2 * page->hres));\n      olength = (uint32)(ilength - (vmargin * 2 * page->vres));\n      }\n    }\n  if (owidth > iwidth)\n    owidth = iwidth;\n  if (olength > ilength)\n    olength = ilength;\n  switch (page->orient)\n    {\n    case ORIENTATION_NONE:\n    case ORIENTATION_PORTRAIT:\n         ocols = TIFFhowmany(iwidth, owidth);\n         orows = TIFFhowmany(ilength, olength);\n         orientation = ORIENTATION_PORTRAIT;\n         break;\n    case ORIENTATION_LANDSCAPE:\n         ocols = TIFFhowmany(iwidth, olength);\n         orows = TIFFhowmany(ilength, owidth);\n         x1 = olength;\n         olength = owidth;\n         owidth = x1;\n         orientation = ORIENTATION_LANDSCAPE;\n         break;\n    case ORIENTATION_AUTO:\n    default:\n         x1 = TIFFhowmany(iwidth, owidth);\n         x2 = TIFFhowmany(ilength, olength);\n         y1 = TIFFhowmany(iwidth, olength);\n         y2 = TIFFhowmany(ilength, owidth);\n         if ( (x1 * x2) < (y1 * y2))\n           {\n           ocols = x1;\n           orows = x2;\n           orientation = ORIENTATION_PORTRAIT;\n\t   }\n         else\n           {\n           ocols = y1;\n           orows = y2;\n           x1 = olength;\n           olength = owidth;\n           owidth = x1;\n           orientation = ORIENTATION_LANDSCAPE;\n           }\n    }\n  if (ocols < 1)\n    ocols = 1;\n  if (orows < 1)\n    orows = 1;\n  if (page->rows < 1)\n    page->rows = orows;\n  if (page->cols < 1)\n    page->cols = ocols;\n  line_bytes = TIFFhowmany8(owidth * image->bps) * image->spp;\n  if ((page->rows * page->cols) > MAX_SECTIONS)\n   {\n   TIFFError("computeOutputPixelOffsets",\n\t     "Rows and Columns exceed maximum sections\\nIncrease resolution or reduce sections");\n   return (-1);\n   }\n  for (k = 0, i = 0 && k <= MAX_SECTIONS; i < orows; i++)\n    {\n    y1 = (uint32)(olength * i);\n    y2 = (uint32)(olength * (i +  1) - 1);\n    if (y2 >= ilength)\n      y2 = ilength - 1;\n    for (j = 0; j < ocols; j++, k++)\n      {\n      x1 = (uint32)(owidth * j);\n      x2 = (uint32)(owidth * (j + 1) - 1);\n      if (x2 >= iwidth)\n        x2 = iwidth - 1;\n      sections[k].x1 = x1;\n      sections[k].x2 = x2;\n      sections[k].y1 = y1;\n      sections[k].y2 = y2;\n      sections[k].buffsize = line_bytes * olength;\n      sections[k].position = k + 1;\n      sections[k].total = orows * ocols;\n      }\n    }\n  return (0);\n  }']