From 28f18b68db1af3668203730ba8cfbb66103fe669 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 29 Sep 2015 14:25:23 +0200 Subject: [PATCH] vcl: replace alloca() with std::unique_ptr Change-Id: I82b982895ee422bcf5a23756df4d81c89bc47636 --- vcl/generic/fontmanager/fontconfig.cxx | 6 ++---- vcl/generic/fontmanager/fontmanager.cxx | 4 +--- vcl/source/font/PhysicalFontCollection.cxx | 5 ++--- vcl/unx/generic/printer/jobdata.cxx | 7 +++---- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx index becb419399b3..f6ee508623c7 100644 --- a/vcl/generic/fontmanager/fontconfig.cxx +++ b/vcl/generic/fontmanager/fontconfig.cxx @@ -53,8 +53,6 @@ using namespace psp; #include "rtl/ustrbuf.hxx" -#include "sal/alloca.h" - #include #include @@ -1086,7 +1084,7 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi // update rMissingCodes by removing resolved unicodes if( !rMissingCodes.isEmpty() ) { - sal_uInt32* pRemainingCodes = static_cast(alloca( rMissingCodes.getLength() * sizeof(sal_uInt32) )); + std::unique_ptr const pRemainingCodes(new sal_uInt32[rMissingCodes.getLength()]); int nRemainingLen = 0; FcCharSet* unicodes; if (!FcPatternGetCharSet(pSet->fonts[0], FC_CHARSET, 0, &unicodes)) @@ -1099,7 +1097,7 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi pRemainingCodes[ nRemainingLen++ ] = nCode; } } - OUString sStillMissing(pRemainingCodes, nRemainingLen); + OUString sStillMissing(pRemainingCodes.get(), nRemainingLen); #if defined(ENABLE_DBUS) && defined(ENABLE_PACKAGEKIT) if (get_xid_for_dbus()) { diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx index 56917f6ea1d4..b6651b7674ff 100644 --- a/vcl/generic/fontmanager/fontmanager.cxx +++ b/vcl/generic/fontmanager/fontmanager.cxx @@ -59,8 +59,6 @@ #include #endif -#include "sal/alloca.h" - #include #include #include @@ -472,7 +470,7 @@ bool PrintFontManager::PrintFont::readAfmMetrics( MultiAtomProvider* pProvider, // first transform the character codes to unicode // note: this only works with single byte encodings - sal_Unicode* pUnicodes = static_cast(alloca( pInfo->numOfChars * sizeof(sal_Unicode))); + std::unique_ptr const pUnicodes(new sal_Unicode[pInfo->numOfChars]); CharMetricInfo* pChar = pInfo->cmi; int i; diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx index 26b33ed02191..cd89bdf0e6a1 100644 --- a/vcl/source/font/PhysicalFontCollection.cxx +++ b/vcl/source/font/PhysicalFontCollection.cxx @@ -18,7 +18,6 @@ */ #include -#include #include @@ -244,7 +243,7 @@ PhysicalFontFamily* PhysicalFontCollection::GetGlyphFallbackFont( FontSelectPatt // there is a matching fallback in the cache // so update rMissingCodes with codepoints not yet resolved by this fallback int nRemainingLength = 0; - sal_UCS4* pRemainingCodes = static_cast(alloca( rMissingCodes.getLength() * sizeof(sal_UCS4) )); + std::unique_ptr const pRemainingCodes(new sal_UCS4[rMissingCodes.getLength()]); OUString aFontName; while( nStrIndex < rMissingCodes.getLength() ) @@ -254,7 +253,7 @@ PhysicalFontFamily* PhysicalFontCollection::GetGlyphFallbackFont( FontSelectPatt if( !bCached || (rFontSelData.maSearchName != aFontName) ) pRemainingCodes[ nRemainingLength++ ] = cChar; } - rMissingCodes = OUString( pRemainingCodes, nRemainingLength ); + rMissingCodes = OUString( pRemainingCodes.get(), nRemainingLength ); } else { diff --git a/vcl/unx/generic/printer/jobdata.cxx b/vcl/unx/generic/printer/jobdata.cxx index 85f587a3fe0d..840ef7b1b516 100644 --- a/vcl/unx/generic/printer/jobdata.cxx +++ b/vcl/unx/generic/printer/jobdata.cxx @@ -22,7 +22,6 @@ #include "vcl/printerinfomanager.hxx" #include "tools/stream.hxx" -#include #include #include @@ -293,9 +292,9 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa { rJobData.m_aContext.setParser( rJobData.m_pParser ); int nBytes = bytes - aStream.Tell(); - char* pRemain = static_cast(alloca( bytes - aStream.Tell() )); - aStream.Read( pRemain, nBytes ); - rJobData.m_aContext.rebuildFromStreamBuffer( pRemain, nBytes ); + std::unique_ptr pRemain(new char[bytes - aStream.Tell()]); + aStream.Read( pRemain.get(), nBytes ); + rJobData.m_aContext.rebuildFromStreamBuffer( pRemain.get(), nBytes ); bContext = true; } }