Commit f197c2dd authored by Bob Friesenhahn's avatar Bob Friesenhahn

* contrib/addtiffo/tif_ovrcache.c (TIFFCreateOvrCache): Fix

Coverity 298615 "Resource leak".
(TIFFGetOvrBlock): Fix Coverity 1024649 "Unintended sign
extension".
parent b22be0db
2015-05-28 Bob Friesenhahn <[email protected]>
* contrib/addtiffo/tif_ovrcache.c (TIFFCreateOvrCache): Fix
Coverity 298615 "Resource leak".
(TIFFGetOvrBlock): Fix Coverity 1024649 "Unintended sign
extension".
* tools/bmp2tiff.c (main): Fix Coverity 1024225 "Untrusted value
as argument".
(main): Fix Coverity 1024678 "Unchecked return value from
......
/******************************************************************************
* $Id: tif_ovrcache.c,v 1.10 2015-05-28 13:26:03 bfriesen Exp $
* $Id: tif_ovrcache.c,v 1.11 2015-05-29 03:08:19 bfriesen Exp $
*
* Project: TIFF Overview Builder
* Purpose: Library functions to maintain two rows of tiles or two strips
......@@ -104,14 +104,15 @@ TIFFOvrCache *TIFFCreateOvrCache( TIFF *hTIFF, toff_t nDirOffset )
psCache->pabyRow2Blocks =
(unsigned char *) _TIFFmalloc(psCache->nBytesPerRow);
if( psCache->pabyRow1Blocks == NULL
|| psCache->pabyRow2Blocks == NULL )
if ( psCache->pabyRow1Blocks == NULL
|| psCache->pabyRow2Blocks == NULL )
{
TIFFErrorExt( hTIFF->tif_clientdata, hTIFF->tif_name,
"Can't allocate memory for overview cache." );
/* TODO: use of TIFFError is inconsistent with use of fprintf in addtiffo.c, sort out */
if (psCache->pabyRow1Blocks) _TIFFfree(psCache->pabyRow1Blocks);
if (psCache->pabyRow2Blocks) _TIFFfree(psCache->pabyRow2Blocks);
_TIFFfree( psCache );
return NULL;
}
......@@ -269,9 +270,9 @@ unsigned char *TIFFGetOvrBlock( TIFFOvrCache *psCache, int iTileX, int iTileY,
int iSample )
{
int nRowOffset;
long nRowOffset;
if( iTileY > psCache->nBlockOffset + 1 )
if ( iTileY > psCache->nBlockOffset + 1 )
TIFFWriteOvrRow( psCache );
assert( iTileX >= 0 && iTileX < psCache->nBlocksPerRow );
......@@ -281,13 +282,13 @@ unsigned char *TIFFGetOvrBlock( TIFFOvrCache *psCache, int iTileX, int iTileY,
assert( iSample >= 0 && iSample < psCache->nSamples );
if (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)
nRowOffset = ((iTileX * psCache->nSamples) + iSample)
* psCache->nBytesPerBlock;
nRowOffset = ((((toff_t) iTileX * psCache->nSamples) + iSample)
* psCache->nBytesPerBlock);
else
nRowOffset = iTileX * psCache->nBytesPerBlock +
(psCache->nBitsPerPixel + 7) / 8 * iSample;
if( iTileY == psCache->nBlockOffset )
if ( iTileY == psCache->nBlockOffset )
return psCache->pabyRow1Blocks + nRowOffset;
else
return psCache->pabyRow2Blocks + nRowOffset;
......@@ -337,7 +338,7 @@ void TIFFDestroyOvrCache( TIFFOvrCache * psCache )
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* c-basic-offset: 4
* fill-column: 78
* End:
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment