From 6983ec39b23ba8261f75b95aa5cd47eec5f5cb66 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Thu, 2 May 2013 15:56:55 +0200 Subject: [PATCH] raster block setIsNoDataExcept fix, fixes #7608 --- src/core/raster/qgsrasterblock.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/raster/qgsrasterblock.cpp b/src/core/raster/qgsrasterblock.cpp index ccc8895f272..6fa363c406b 100644 --- a/src/core/raster/qgsrasterblock.cpp +++ b/src/core/raster/qgsrasterblock.cpp @@ -75,6 +75,7 @@ QgsRasterBlock::QgsRasterBlock( QGis::DataType theDataType, int theWidth, int th QgsRasterBlock::~QgsRasterBlock() { + QgsDebugMsg( QString( "mData = %1" ).arg(( ulong )mData ) ); qgsFree( mData ); delete mImage; qgsFree( mNoDataBitmap ); @@ -474,10 +475,10 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect ) int bottom = theExceptRect.bottom(); int left = theExceptRect.left(); int right = theExceptRect.right(); - if ( top < 0 ) top = 0; - if ( left < 0 ) left = 0; - if ( bottom >= mHeight ) bottom = mHeight - 1; - if ( right >= mWidth ) right = mWidth - 1; + top = qMin( qMax( top, 0 ), mHeight - 1 ); + left = qMin( qMax( left, 0 ), mWidth - 1 ); + bottom = qMax( 0, qMin( bottom, mHeight - 1 ) ); + right = qMax( 0, qMin( right, mWidth - 1 ) ); QgsDebugMsg( "Entered" ); if ( typeIsNumeric( mDataType ) ) @@ -511,12 +512,12 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect ) // middle for ( int r = top; r <= bottom; r++ ) { - size_t i = r * mWidth; + size_t i = ( size_t )r * mWidth; // middle left memcpy(( char* )mData + i*dataTypeSize, nodataRow, dataTypeSize*left ); // middle right i += right + 1; - int w = mWidth - right; + int w = mWidth - right - 1; memcpy(( char* )mData + i*dataTypeSize, nodataRow, dataTypeSize*w ); } delete [] nodataRow;