tools/tiffcrop.c:6452: error: Null Dereference
  pointer `crop_buff` last assigned on line 6450 could be null and is dereferenced by call to `_TIFFmemset()` at line 6452, column 5.

tools/tiffcrop.c:6428:1: start of procedure createCroppedImage()
6426.  * the most optimized path when no Zones or Regions are required.
6427.  */
6428. static int
      ^
6429. createCroppedImage(struct image_data *image, struct crop_mask *crop, 
6430.                    unsigned char **read_buff_ptr, unsigned char **crop_buff_ptr)

tools/tiffcrop.c:6433:3: 
6431.   {
6432.   tsize_t   cropsize;
6433.   unsigned  char *read_buff = NULL;
        ^
6434.   unsigned  char *crop_buff = NULL;
6435.   unsigned  char *new_buff  = NULL;

tools/tiffcrop.c:6434:3: 
6432.   tsize_t   cropsize;
6433.   unsigned  char *read_buff = NULL;
6434.   unsigned  char *crop_buff = NULL;
        ^
6435.   unsigned  char *new_buff  = NULL;
6436.   static    tsize_t  prev_cropsize = 0;

tools/tiffcrop.c:6435:3: 
6433.   unsigned  char *read_buff = NULL;
6434.   unsigned  char *crop_buff = NULL;
6435.   unsigned  char *new_buff  = NULL;
        ^
6436.   static    tsize_t  prev_cropsize = 0;
6437. 

tools/tiffcrop.c:6436:3: 
6434.   unsigned  char *crop_buff = NULL;
6435.   unsigned  char *new_buff  = NULL;
6436.   static    tsize_t  prev_cropsize = 0;
        ^
6437. 
6438.   read_buff = *read_buff_ptr;

tools/tiffcrop.c:6438:3: 
6436.   static    tsize_t  prev_cropsize = 0;
6437. 
6438.   read_buff = *read_buff_ptr;
        ^
6439. 
6440.   /* process full image, no crop buffer needed */

tools/tiffcrop.c:6441:3: 
6439. 
6440.   /* process full image, no crop buffer needed */
6441.   crop_buff = read_buff;
        ^
6442.   *crop_buff_ptr = read_buff;
6443.   crop->combined_width = image->width;

tools/tiffcrop.c:6442:3: 
6440.   /* process full image, no crop buffer needed */
6441.   crop_buff = read_buff;
6442.   *crop_buff_ptr = read_buff;
        ^
6443.   crop->combined_width = image->width;
6444.   crop->combined_length = image->length;

tools/tiffcrop.c:6443:3: 
6441.   crop_buff = read_buff;
6442.   *crop_buff_ptr = read_buff;
6443.   crop->combined_width = image->width;
        ^
6444.   crop->combined_length = image->length;
6445. 

tools/tiffcrop.c:6444:3: 
6442.   *crop_buff_ptr = read_buff;
6443.   crop->combined_width = image->width;
6444.   crop->combined_length = image->length;
        ^
6445. 
6446.   cropsize = crop->bufftotal;

tools/tiffcrop.c:6446:3: 
6444.   crop->combined_length = image->length;
6445. 
6446.   cropsize = crop->bufftotal;
        ^
6447.   crop_buff = *crop_buff_ptr;
6448.   if (!crop_buff)

tools/tiffcrop.c:6447:3: 
6445. 
6446.   cropsize = crop->bufftotal;
6447.   crop_buff = *crop_buff_ptr;
        ^
6448.   if (!crop_buff)
6449.     {

tools/tiffcrop.c:6448:8: Taking true branch
6446.   cropsize = crop->bufftotal;
6447.   crop_buff = *crop_buff_ptr;
6448.   if (!crop_buff)
             ^
6449.     {
6450.     crop_buff = (unsigned char *)_TIFFmalloc(cropsize);

tools/tiffcrop.c:6450:5: 
6448.   if (!crop_buff)
6449.     {
6450.     crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
          ^
6451.     *crop_buff_ptr = crop_buff;
6452.     _TIFFmemset(crop_buff, 0, cropsize);

libtiff/tif_unix.c:253:1: start of procedure _TIFFmalloc()
  251. #endif
  252. 
  253. void*
       ^
  254. _TIFFmalloc(tmsize_t s)
  255. {

libtiff/tif_unix.c:256:2: 
  254. _TIFFmalloc(tmsize_t s)
  255. {
  256. 	return (malloc((size_t) s));
        ^
  257. }
  258. 

libtiff/tif_unix.c:257:1: return from a call to _TIFFmalloc
  255. {
  256. 	return (malloc((size_t) s));
  257. }
       ^
  258. 
  259. void

tools/tiffcrop.c:6451:5: 
6449.     {
6450.     crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
6451.     *crop_buff_ptr = crop_buff;
          ^
6452.     _TIFFmemset(crop_buff, 0, cropsize);
6453.     prev_cropsize = cropsize;

tools/tiffcrop.c:6452:5: 
6450.     crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
6451.     *crop_buff_ptr = crop_buff;
6452.     _TIFFmemset(crop_buff, 0, cropsize);
          ^
6453.     prev_cropsize = cropsize;
6454.     }

libtiff/tif_unix.c:271:1: start of procedure _TIFFmemset()
  269. }
  270. 
  271. void
       ^
  272. _TIFFmemset(void* p, int v, tmsize_t c)
  273. {

libtiff/tif_unix.c:274:2: 
  272. _TIFFmemset(void* p, int v, tmsize_t c)
  273. {
  274. 	memset(p, v, (size_t) c);
        ^
  275. }
  276. 

libtiff/tif_unix.c:275:1: return from a call to _TIFFmemset
  273. {
  274. 	memset(p, v, (size_t) c);
  275. }
       ^
  276. 
  277. void

static int
createCroppedImage(struct image_data *image, struct crop_mask *crop,
                   unsigned char **read_buff_ptr, unsigned char **crop_buff_ptr)
  {
  tsize_t   cropsize;
  unsigned  char *read_buff = NULL;
  unsigned  char *crop_buff = NULL;
  unsigned  char *new_buff  = NULL;
  static    tsize_t  prev_cropsize = 0;
  read_buff = *read_buff_ptr;
  crop_buff = read_buff;
  *crop_buff_ptr = read_buff;
  crop->combined_width = image->width;
  crop->combined_length = image->length;
  cropsize = crop->bufftotal;
  crop_buff = *crop_buff_ptr;
  if (!crop_buff)
    {
    crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
    *crop_buff_ptr = crop_buff;
    _TIFFmemset(crop_buff, 0, cropsize);
    prev_cropsize = cropsize;
    }
  else
    {
    if (prev_cropsize < cropsize)
      {
      new_buff = _TIFFrealloc(crop_buff, cropsize);
      if (!new_buff)
        {
	free (crop_buff);
        crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
        }
      else
        crop_buff = new_buff;
      _TIFFmemset(crop_buff, 0, cropsize);
      }
    }
  if (!crop_buff)
    {
    TIFFError("createCroppedImage", "Unable to allocate/reallocate crop buffer");
    return (-1);
    }
  *crop_buff_ptr = crop_buff;
  if (crop->crop_mode & CROP_INVERT)
    {
    switch (crop->photometric)
      {
      case PHOTOMETRIC_MINISWHITE:
      case PHOTOMETRIC_MINISBLACK:
	   image->photometric = crop->photometric;
	   break;
      case INVERT_DATA_ONLY:
      case INVERT_DATA_AND_TAG:
           if (invertImage(image->photometric, image->spp, image->bps,
                           crop->combined_width, crop->combined_length, crop_buff))
             {
             TIFFError("createCroppedImage",
                       "Failed to invert colorspace for image or cropped selection");
             return (-1);
             }
           if (crop->photometric == INVERT_DATA_AND_TAG)
             {
             switch (image->photometric)
               {
               case PHOTOMETRIC_MINISWHITE:
 	            image->photometric = PHOTOMETRIC_MINISBLACK;
	            break;
               case PHOTOMETRIC_MINISBLACK:
 	            image->photometric = PHOTOMETRIC_MINISWHITE;
	            break;
               default:
	            break;
	       }
	     }
           break;
      default: break;
      }
    }
  if (crop->crop_mode & CROP_MIRROR)
    {
    if (mirrorImage(image->spp, image->bps, crop->mirror,
                    crop->combined_width, crop->combined_length, crop_buff))
      {
      TIFFError("createCroppedImage", "Failed to mirror image or cropped selection %s",
	       (crop->rotation == MIRROR_HORIZ) ? "horizontally" : "vertically");
      return (-1);
      }
    }
  if (crop->crop_mode & CROP_ROTATE)
    {
    if (rotateImage(crop->rotation, image, &crop->combined_width,
                    &crop->combined_length, crop_buff_ptr))
      {
      TIFFError("createCroppedImage",
                "Failed to rotate image or cropped selection by %d degrees", crop->rotation);
      return (-1);
      }
    }
  if (crop_buff == read_buff)
    *read_buff_ptr = NULL;
  return (0);
  }
['static int\ncreateCroppedImage(struct image_data *image, struct crop_mask *crop,\n                   unsigned char **read_buff_ptr, unsigned char **crop_buff_ptr)\n  {\n  tsize_t   cropsize;\n  unsigned  char *read_buff = NULL;\n  unsigned  char *crop_buff = NULL;\n  unsigned  char *new_buff  = NULL;\n  static    tsize_t  prev_cropsize = 0;\n  read_buff = *read_buff_ptr;\n  crop_buff = read_buff;\n  *crop_buff_ptr = read_buff;\n  crop->combined_width = image->width;\n  crop->combined_length = image->length;\n  cropsize = crop->bufftotal;\n  crop_buff = *crop_buff_ptr;\n  if (!crop_buff)\n    {\n    crop_buff = (unsigned char *)_TIFFmalloc(cropsize);\n    *crop_buff_ptr = crop_buff;\n    _TIFFmemset(crop_buff, 0, cropsize);\n    prev_cropsize = cropsize;\n    }\n  else\n    {\n    if (prev_cropsize < cropsize)\n      {\n      new_buff = _TIFFrealloc(crop_buff, cropsize);\n      if (!new_buff)\n        {\n\tfree (crop_buff);\n        crop_buff = (unsigned char *)_TIFFmalloc(cropsize);\n        }\n      else\n        crop_buff = new_buff;\n      _TIFFmemset(crop_buff, 0, cropsize);\n      }\n    }\n  if (!crop_buff)\n    {\n    TIFFError("createCroppedImage", "Unable to allocate/reallocate crop buffer");\n    return (-1);\n    }\n  *crop_buff_ptr = crop_buff;\n  if (crop->crop_mode & CROP_INVERT)\n    {\n    switch (crop->photometric)\n      {\n      case PHOTOMETRIC_MINISWHITE:\n      case PHOTOMETRIC_MINISBLACK:\n\t   image->photometric = crop->photometric;\n\t   break;\n      case INVERT_DATA_ONLY:\n      case INVERT_DATA_AND_TAG:\n           if (invertImage(image->photometric, image->spp, image->bps,\n                           crop->combined_width, crop->combined_length, crop_buff))\n             {\n             TIFFError("createCroppedImage",\n                       "Failed to invert colorspace for image or cropped selection");\n             return (-1);\n             }\n           if (crop->photometric == INVERT_DATA_AND_TAG)\n             {\n             switch (image->photometric)\n               {\n               case PHOTOMETRIC_MINISWHITE:\n \t            image->photometric = PHOTOMETRIC_MINISBLACK;\n\t            break;\n               case PHOTOMETRIC_MINISBLACK:\n \t            image->photometric = PHOTOMETRIC_MINISWHITE;\n\t            break;\n               default:\n\t            break;\n\t       }\n\t     }\n           break;\n      default: break;\n      }\n    }\n  if (crop->crop_mode & CROP_MIRROR)\n    {\n    if (mirrorImage(image->spp, image->bps, crop->mirror,\n                    crop->combined_width, crop->combined_length, crop_buff))\n      {\n      TIFFError("createCroppedImage", "Failed to mirror image or cropped selection %s",\n\t       (crop->rotation == MIRROR_HORIZ) ? "horizontally" : "vertically");\n      return (-1);\n      }\n    }\n  if (crop->crop_mode & CROP_ROTATE)\n    {\n    if (rotateImage(crop->rotation, image, &crop->combined_width,\n                    &crop->combined_length, crop_buff_ptr))\n      {\n      TIFFError("createCroppedImage",\n                "Failed to rotate image or cropped selection by %d degrees", crop->rotation);\n      return (-1);\n      }\n    }\n  if (crop_buff == read_buff)\n    *read_buff_ptr = NULL;\n  return (0);\n  }', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n\treturn (malloc((size_t) s));\n}', 'void\n_TIFFmemset(void* p, int v, tmsize_t c)\n{\n\tmemset(p, v, (size_t) c);\n}']