summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-06-02 11:04:41 +0200
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-12-18 01:07:39 -0500
commitdcbad5d45e9c658766f9b165020db8fb612d4f6e (patch)
tree94d8338c0f40df5cfcf9c69a41870364d56d82cc
parent10ac3111dce63e0f651f12f0943e5054feb36a08 (diff)
no need to assign a nullptr after a bad_alloc
since if the allocation failed, the assignment would never happen Also use early exit to simplify the code in X11SalBitmap::ImplCreateDIB Change-Id: I73301bfad6492c2b42c08744c24cfb78237983f0 Reviewed-on: https://gerrit.libreoffice.org/38346 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit 5c0cee64b9430da404fa52988871fae6a5dd9f41) (cherry picked from commit e368f98d44fe0715b0fff0cbbcc1f891880631d0)
-rw-r--r--vcl/headless/svpbmp.cxx5
-rw-r--r--vcl/unx/generic/gdi/salbmp.cxx165
2 files changed, 81 insertions, 89 deletions
diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx
index ad14169b7243..c3ba02f57528 100644
--- a/vcl/headless/svpbmp.cxx
+++ b/vcl/headless/svpbmp.cxx
@@ -64,11 +64,8 @@ BitmapBuffer* ImplCreateDIB(
}
catch (const std::bad_alloc&)
{
- pDIB = nullptr;
- }
-
- if(!pDIB)
return nullptr;
+ }
const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx
index fbd0ec07b353..049c13d0ff7e 100644
--- a/vcl/unx/generic/gdi/salbmp.cxx
+++ b/vcl/unx/generic/gdi/salbmp.cxx
@@ -135,105 +135,100 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB(
BitmapBuffer* pDIB = nullptr;
- if( rSize.Width() && rSize.Height() )
+ if( !rSize.Width() || !rSize.Height() )
+ return nullptr;
+
+ try
{
- try
- {
- pDIB = new BitmapBuffer;
- }
- catch (const std::bad_alloc&)
- {
- pDIB = nullptr;
- }
+ pDIB = new BitmapBuffer;
+ }
+ catch (const std::bad_alloc&)
+ {
+ return nullptr;
+ }
- if( pDIB )
- {
- const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
+ const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
- pDIB->mnFormat = ScanlineFormat::NONE;
+ pDIB->mnFormat = ScanlineFormat::NONE;
- switch( nBitCount )
- {
- case 1: pDIB->mnFormat |= ScanlineFormat::N1BitMsbPal; break;
- case 4: pDIB->mnFormat |= ScanlineFormat::N4BitMsnPal; break;
- case 8: pDIB->mnFormat |= ScanlineFormat::N8BitPal; break;
+ switch( nBitCount )
+ {
+ case 1: pDIB->mnFormat |= ScanlineFormat::N1BitMsbPal; break;
+ case 4: pDIB->mnFormat |= ScanlineFormat::N4BitMsnPal; break;
+ case 8: pDIB->mnFormat |= ScanlineFormat::N8BitPal; break;
#ifdef OSL_BIGENDIAN
- case 16:
- {
- pDIB->mnFormat|= ScanlineFormat::N16BitTcMsbMask;
- ColorMaskElement aRedMask(0xf800);
- aRedMask.CalcMaskShift();
- ColorMaskElement aGreenMask(0x07e0);
- aGreenMask.CalcMaskShift();
- ColorMaskElement aBlueMask(0x001f);
- aBlueMask.CalcMaskShift();
- pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
- break;
- }
+ case 16:
+ {
+ pDIB->mnFormat|= ScanlineFormat::N16BitTcMsbMask;
+ ColorMaskElement aRedMask(0xf800);
+ aRedMask.CalcMaskShift();
+ ColorMaskElement aGreenMask(0x07e0);
+ aGreenMask.CalcMaskShift();
+ ColorMaskElement aBlueMask(0x001f);
+ aBlueMask.CalcMaskShift();
+ pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
+ break;
+ }
#else
- case 16:
- {
- pDIB->mnFormat|= ScanlineFormat::N16BitTcLsbMask;
- ColorMaskElement aRedMask(0xf800);
- aRedMask.CalcMaskShift();
- ColorMaskElement aGreenMask(0x07e0);
- aGreenMask.CalcMaskShift();
- ColorMaskElement aBlueMask(0x001f);
- aBlueMask.CalcMaskShift();
- pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
- break;
- }
+ case 16:
+ {
+ pDIB->mnFormat|= ScanlineFormat::N16BitTcLsbMask;
+ ColorMaskElement aRedMask(0xf800);
+ aRedMask.CalcMaskShift();
+ ColorMaskElement aGreenMask(0x07e0);
+ aGreenMask.CalcMaskShift();
+ ColorMaskElement aBlueMask(0x001f);
+ aBlueMask.CalcMaskShift();
+ pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
+ break;
+ }
#endif
- default:
- nBitCount = 24;
- SAL_FALLTHROUGH;
- case 24:
- pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr;
- break;
- }
+ default:
+ nBitCount = 24;
+ SAL_FALLTHROUGH;
+ case 24:
+ pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr;
+ break;
+ }
- pDIB->mnWidth = rSize.Width();
- pDIB->mnHeight = rSize.Height();
- long nScanlineBase;
- bool bFail = o3tl::checked_multiply<long>(pDIB->mnWidth, nBitCount, nScanlineBase);
- if (bFail)
- {
- SAL_WARN("vcl.gdi", "checked multiply failed");
- delete pDIB;
- return nullptr;
- }
- pDIB->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase);
- if (pDIB->mnScanlineSize < nScanlineBase/8)
- {
- SAL_WARN("vcl.gdi", "scanline calculation wraparound");
- delete pDIB;
- return nullptr;
- }
- pDIB->mnBitCount = nBitCount;
+ pDIB->mnWidth = rSize.Width();
+ pDIB->mnHeight = rSize.Height();
+ long nScanlineBase;
+ bool bFail = o3tl::checked_multiply<long>(pDIB->mnWidth, nBitCount, nScanlineBase);
+ if (bFail)
+ {
+ SAL_WARN("vcl.gdi", "checked multiply failed");
+ delete pDIB;
+ return nullptr;
+ }
+ pDIB->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase);
+ if (pDIB->mnScanlineSize < nScanlineBase/8)
+ {
+ SAL_WARN("vcl.gdi", "scanline calculation wraparound");
+ delete pDIB;
+ return nullptr;
+ }
+ pDIB->mnBitCount = nBitCount;
- if( nColors )
- {
- pDIB->maPalette = rPal;
- pDIB->maPalette.SetEntryCount( nColors );
- }
+ if( nColors )
+ {
+ pDIB->maPalette = rPal;
+ pDIB->maPalette.SetEntryCount( nColors );
+ }
- try
- {
- pDIB->mpBits = new sal_uInt8[ pDIB->mnScanlineSize * pDIB->mnHeight ];
+ try
+ {
+ pDIB->mpBits = new sal_uInt8[ pDIB->mnScanlineSize * pDIB->mnHeight ];
#if defined HAVE_VALGRIND_HEADERS
- if (RUNNING_ON_VALGRIND)
- blankExtraSpace(pDIB);
+ if (RUNNING_ON_VALGRIND)
+ blankExtraSpace(pDIB);
#endif
- }
- catch (const std::bad_alloc&)
- {
- delete pDIB;
- pDIB = nullptr;
- }
- }
}
- else
+ catch (const std::bad_alloc&)
+ {
+ delete pDIB;
pDIB = nullptr;
+ }
return pDIB;
}