diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-01-05 03:24:16 -0600 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-01-05 03:24:49 -0600 |
commit | bb0438f010893b6bc083aac6c1037f9a80ae8add (patch) | |
tree | 15830351698178dcc61e76369c90bcd5ed8e9821 /vcl/source/gdi/bitmap3.cxx | |
parent | 42b50a1234f2047e4d4eb4c4da37919eb61a047e (diff) |
potential null pointer dereference
Diffstat (limited to 'vcl/source/gdi/bitmap3.cxx')
-rw-r--r-- | vcl/source/gdi/bitmap3.cxx | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index 19f5f255ec63..a2b8587087e2 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -949,63 +949,65 @@ sal_Bool Bitmap::ImplScaleFast( const double& rScaleX, const double& rScaleY ) const Size aSizePix( GetSizePixel() ); const long nNewWidth = FRound( aSizePix.Width() * rScaleX ); const long nNewHeight = FRound( aSizePix.Height() * rScaleY ); - sal_Bool bRet = sal_False; + sal_Bool bRet = sal_False; if( nNewWidth && nNewHeight ) { BitmapReadAccess* pReadAcc = AcquireReadAccess(); - Bitmap aNewBmp( Size( nNewWidth, nNewHeight ), GetBitCount(), &pReadAcc->GetPalette() ); - BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); - if( pReadAcc && pWriteAcc ) + if(pReadAcc) { - const long nScanlineSize = pWriteAcc->GetScanlineSize(); - const long nNewWidth1 = nNewWidth - 1L; - const long nNewHeight1 = nNewHeight - 1L; - const long nWidth = pReadAcc->Width(); - const long nHeight = pReadAcc->Height(); - long* pLutX = new long[ nNewWidth ]; - long* pLutY = new long[ nNewHeight ]; - - if( nNewWidth1 && nNewHeight1 ) - { - long nX, nY, nMapY, nActY = 0L; - - for( nX = 0L; nX < nNewWidth; nX++ ) - pLutX[ nX ] = nX * nWidth / nNewWidth; - - for( nY = 0L; nY < nNewHeight; nY++ ) - pLutY[ nY ] = nY * nHeight / nNewHeight; + Bitmap aNewBmp( Size( nNewWidth, nNewHeight ), GetBitCount(), &pReadAcc->GetPalette() ); + BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); - while( nActY < nNewHeight ) + if( pWriteAcc ) + { + const long nScanlineSize = pWriteAcc->GetScanlineSize(); + const long nNewWidth1 = nNewWidth - 1L; + const long nNewHeight1 = nNewHeight - 1L; + const long nWidth = pReadAcc->Width(); + const long nHeight = pReadAcc->Height(); + long* pLutX = new long[ nNewWidth ]; + long* pLutY = new long[ nNewHeight ]; + + if( nNewWidth1 && nNewHeight1 ) { - nMapY = pLutY[ nActY ]; + long nX, nY, nMapY, nActY = 0L; for( nX = 0L; nX < nNewWidth; nX++ ) - pWriteAcc->SetPixel( nActY, nX, pReadAcc->GetPixel( nMapY , pLutX[ nX ] ) ); + pLutX[ nX ] = nX * nWidth / nNewWidth; + + for( nY = 0L; nY < nNewHeight; nY++ ) + pLutY[ nY ] = nY * nHeight / nNewHeight; - while( ( nActY < nNewHeight1 ) && ( pLutY[ nActY + 1 ] == nMapY ) ) + while( nActY < nNewHeight ) { - memcpy( pWriteAcc->GetScanline( nActY + 1L ), - pWriteAcc->GetScanline( nActY ), nScanlineSize ); + nMapY = pLutY[ nActY ]; + + for( nX = 0L; nX < nNewWidth; nX++ ) + pWriteAcc->SetPixel( nActY, nX, pReadAcc->GetPixel( nMapY , pLutX[ nX ] ) ); + + while( ( nActY < nNewHeight1 ) && ( pLutY[ nActY + 1 ] == nMapY ) ) + { + memcpy( pWriteAcc->GetScanline( nActY + 1L ), + pWriteAcc->GetScanline( nActY ), nScanlineSize ); + nActY++; + } nActY++; } - nActY++; + bRet = sal_True; + aNewBmp.ReleaseAccess( pWriteAcc ); } - bRet = sal_True; + delete[] pLutX; + delete[] pLutY; } + ReleaseAccess( pReadAcc ); - delete[] pLutX; - delete[] pLutY; + if( bRet ) + ImplAssignWithSize( aNewBmp ); } - - ReleaseAccess( pReadAcc ); - aNewBmp.ReleaseAccess( pWriteAcc ); - - if( bRet ) - ImplAssignWithSize( aNewBmp ); } return bRet; |