summaryrefslogtreecommitdiffstats
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-12-23 17:53:50 +0000
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-12-18 01:07:37 -0500
commitffafd1494084626081e37da1d37c1b2f78c752cb (patch)
tree93992c6e6f17c8d8a1d87a4307abafe53c05cc21 /vcl
parentmove the exception handling (diff)
downloadcore-ffafd1494084626081e37da1d37c1b2f78c752cb.tar.gz
core-ffafd1494084626081e37da1d37c1b2f78c752cb.zip
unroll code for early returns, no logic changed intended
(cherry picked from commit 218179ddbffbc4d4a1e96dfaeebca19cffda5f9c) Change-Id: Ic1cc63a5fe3ad2c949f91c395c00f5f99bd7602a (cherry picked from commit ea08f30d999af015390c6767310e2462e7f33711)
Diffstat (limited to 'vcl')
-rw-r--r--vcl/headless/svpbmp.cxx196
1 files changed, 97 insertions, 99 deletions
diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx
index 94f795539011..ef175e8838f3 100644
--- a/vcl/headless/svpbmp.cxx
+++ b/vcl/headless/svpbmp.cxx
@@ -53,119 +53,117 @@ BitmapBuffer* ImplCreateDIB(
|| nBitCount == 32)
&& "Unsupported BitCount!");
+ if (!rSize.Width() || !rSize.Height())
+ return nullptr;
+
BitmapBuffer* pDIB = nullptr;
- if( rSize.Width() && rSize.Height() )
+ try
{
- try
+ pDIB = new BitmapBuffer;
+ }
+ catch (const std::bad_alloc&)
+ {
+ pDIB = nullptr;
+ }
+
+ if(!pDIB)
+ return nullptr;
+
+ const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
+
+ switch (nBitCount)
+ {
+ case 1:
+ pDIB->mnFormat = ScanlineFormat::N1BitLsbPal;
+ break;
+ case 4:
+ pDIB->mnFormat = ScanlineFormat::N4BitMsnPal;
+ break;
+ case 8:
+ pDIB->mnFormat = ScanlineFormat::N8BitPal;
+ break;
+ case 16:
{
- pDIB = new BitmapBuffer;
+#ifdef OSL_BIGENDIAN
+ pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask;
+#else
+ pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask;
+#endif
+ ColorMaskElement aRedMask(0xf800);
+ aRedMask.CalcMaskShift();
+ ColorMaskElement aGreenMask(0x07e0);
+ aGreenMask.CalcMaskShift();
+ ColorMaskElement aBlueMask(0x001f);
+ aBlueMask.CalcMaskShift();
+ pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
+ break;
}
- catch (const std::bad_alloc&)
+ default:
+ nBitCount = 32;
+ SAL_FALLTHROUGH;
+ case 32:
{
- pDIB = nullptr;
+ pDIB->mnFormat = SVP_CAIRO_FORMAT;
+ break;
}
+ }
- if( pDIB )
+ pDIB->mnFormat |= ScanlineFormat::TopDown;
+ 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 );
+ }
+
+ try
+ {
+ size_t size;
+ bFail = o3tl::checked_multiply<size_t>(pDIB->mnHeight, pDIB->mnScanlineSize, size);
+ SAL_WARN_IF(bFail, "vcl.gdi", "checked multiply failed");
+ if (bFail)
{
- const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
-
- switch (nBitCount)
- {
- case 1:
- pDIB->mnFormat = ScanlineFormat::N1BitLsbPal;
- break;
- case 4:
- pDIB->mnFormat = ScanlineFormat::N4BitMsnPal;
- break;
- case 8:
- pDIB->mnFormat = ScanlineFormat::N8BitPal;
- break;
- case 16:
- {
-#ifdef OSL_BIGENDIAN
- pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask;
-#else
- pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask;
-#endif
- ColorMaskElement aRedMask(0xf800);
- aRedMask.CalcMaskShift();
- ColorMaskElement aGreenMask(0x07e0);
- aGreenMask.CalcMaskShift();
- ColorMaskElement aBlueMask(0x001f);
- aBlueMask.CalcMaskShift();
- pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
- break;
- }
- default:
- nBitCount = 32;
- SAL_FALLTHROUGH;
- case 32:
- {
- pDIB->mnFormat = SVP_CAIRO_FORMAT;
- break;
- }
- }
-
- pDIB->mnFormat |= ScanlineFormat::TopDown;
- 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 );
- }
-
- try
- {
- size_t size;
- bFail = o3tl::checked_multiply<size_t>(pDIB->mnHeight, pDIB->mnScanlineSize, size);
- SAL_WARN_IF(bFail, "vcl.gdi", "checked multiply failed");
- if (bFail)
- {
- delete pDIB;
- return nullptr;
- }
-
- pDIB->mpBits = new sal_uInt8[size];
+ delete pDIB;
+ return nullptr;
+ }
+
+ pDIB->mpBits = new sal_uInt8[size];
#ifdef __SANITIZE_ADDRESS__
- if (!pDIB->mpBits)
- { // can only happen with ASAN allocator_may_return_null=1
- delete pDIB;
- pDIB = nullptr;
- }
- else
+ if (!pDIB->mpBits)
+ { // can only happen with ASAN allocator_may_return_null=1
+ delete pDIB;
+ pDIB = nullptr;
+ }
+ else
#endif
- {
- std::memset(pDIB->mpBits, 0, size);
- }
- }
- catch (const std::bad_alloc&)
- {
- delete pDIB;
- pDIB = nullptr;
- }
+ {
+ std::memset(pDIB->mpBits, 0, size);
}
}
- else
+ catch (const std::bad_alloc&)
+ {
+ delete pDIB;
pDIB = nullptr;
+ }
return pDIB;
}