vcl: no raw pointers
For ImplJobSetup. Also, check memcmp mem size more properly Change-Id: Idcf20bf1b51bc2508f3d37e018efd18e591a6099 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/26648 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
This commit is contained in:
parent
c75cac8523
commit
d97e045891
9 changed files with 38 additions and 65 deletions
|
@ -146,21 +146,13 @@ static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
|
|||
}
|
||||
|
||||
// copy the whole context
|
||||
if( pJobSetup->GetDriverData() )
|
||||
std::free( const_cast<sal_uInt8*>(pJobSetup->GetDriverData()) );
|
||||
|
||||
sal_uInt32 nBytes;
|
||||
void* pBuffer = nullptr;
|
||||
std::unique_ptr<sal_uInt8[]> pBuffer;
|
||||
if( rData.getStreamBuffer( pBuffer, nBytes ) )
|
||||
{
|
||||
pJobSetup->SetDriverDataLen( nBytes );
|
||||
pJobSetup->SetDriverData( static_cast<sal_uInt8*>(pBuffer) );
|
||||
}
|
||||
pJobSetup->SetDriverData( std::move(pBuffer), nBytes );
|
||||
else
|
||||
{
|
||||
pJobSetup->SetDriverDataLen( 0 );
|
||||
pJobSetup->SetDriverData( nullptr );
|
||||
}
|
||||
pJobSetup->SetDriverData( nullptr, 0 );
|
||||
}
|
||||
|
||||
// SalInstance
|
||||
|
|
|
@ -69,7 +69,7 @@ struct VCL_DLLPUBLIC JobData
|
|||
|
||||
// creates a new buffer using new
|
||||
// it is up to the user to delete it again
|
||||
bool getStreamBuffer( void*& pData, sal_uInt32& bytes );
|
||||
bool getStreamBuffer( std::unique_ptr<sal_uInt8[]>& pData, sal_uInt32& bytes );
|
||||
static bool constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, JobData& rJobData );
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <vcl/dllapi.h>
|
||||
#include <vcl/prntypes.hxx>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
// see com.sun.star.portal.client.JobSetupSystem.idl:
|
||||
#define JOBSETUP_SYSTEM_WINDOWS 1
|
||||
|
@ -44,7 +45,7 @@ private:
|
|||
tools::Long mnPaperWidth; //< paper width (100th mm)
|
||||
tools::Long mnPaperHeight; //< paper height (100th mm)
|
||||
sal_uInt32 mnDriverDataLen; //< length of system specific data
|
||||
sal_uInt8* mpDriverData; //< system specific data (will be streamed a byte block)
|
||||
std::unique_ptr<sal_uInt8[]> mpDriverData; //< system specific data (will be streamed a byte block)
|
||||
bool mbPapersizeFromSetup;
|
||||
// setup mode
|
||||
PrinterSetupMode meSetupMode;
|
||||
|
@ -86,10 +87,8 @@ public:
|
|||
void SetPaperHeight(tools::Long nHeight);
|
||||
|
||||
sal_uInt32 GetDriverDataLen() const { return mnDriverDataLen; }
|
||||
void SetDriverDataLen(sal_uInt32 nDriverDataLen);
|
||||
|
||||
const sal_uInt8* GetDriverData() const { return mpDriverData; }
|
||||
void SetDriverData(sal_uInt8* pDriverData);
|
||||
const sal_uInt8* GetDriverData() const { return mpDriverData.get(); }
|
||||
void SetDriverData(std::unique_ptr<sal_uInt8[]> pDriverData, sal_uInt32 nDriverDataLen);
|
||||
|
||||
bool GetPapersizeFromSetup() const { return mbPapersizeFromSetup; }
|
||||
void SetPapersizeFromSetup(bool bPapersizeFromSetup);
|
||||
|
|
|
@ -190,8 +190,7 @@ bool AquaSalInfoPrinter::SetPrinterData( ImplJobSetup* io_pSetupData )
|
|||
io_pSetupData->SetOrientation( mePageOrientation );
|
||||
|
||||
io_pSetupData->SetPaperBin( 0 );
|
||||
io_pSetupData->SetDriverData( static_cast<sal_uInt8*>(std::malloc( 4 )) );
|
||||
io_pSetupData->SetDriverDataLen( 4 );
|
||||
io_pSetupData->SetDriverData( std::make_unique<sal_uInt8[]>(4), 4 );
|
||||
}
|
||||
else
|
||||
bSuccess = false;
|
||||
|
|
|
@ -65,7 +65,6 @@ ImplJobSetup::ImplJobSetup()
|
|||
mnPaperWidth = 0;
|
||||
mnPaperHeight = 0;
|
||||
mnDriverDataLen = 0;
|
||||
mpDriverData = nullptr;
|
||||
mbPapersizeFromSetup = false;
|
||||
meSetupMode = PrinterSetupMode::DocumentGlobal;
|
||||
}
|
||||
|
@ -81,14 +80,15 @@ ImplJobSetup::ImplJobSetup( const ImplJobSetup& rJobSetup ) :
|
|||
mnPaperWidth( rJobSetup.GetPaperWidth() ),
|
||||
mnPaperHeight( rJobSetup.GetPaperHeight() ),
|
||||
mnDriverDataLen( rJobSetup.GetDriverDataLen() ),
|
||||
mpDriverData(),
|
||||
mbPapersizeFromSetup( rJobSetup.GetPapersizeFromSetup() ),
|
||||
meSetupMode( rJobSetup.GetPrinterSetupMode() ),
|
||||
maValueMap( rJobSetup.GetValueMap() )
|
||||
{
|
||||
if ( rJobSetup.GetDriverData() )
|
||||
{
|
||||
mpDriverData = static_cast<sal_uInt8*>(std::malloc( mnDriverDataLen ));
|
||||
memcpy( mpDriverData, rJobSetup.GetDriverData(), mnDriverDataLen );
|
||||
mpDriverData.reset( new sal_uInt8[mnDriverDataLen] );
|
||||
memcpy( mpDriverData.get(), rJobSetup.GetDriverData(), mnDriverDataLen );
|
||||
}
|
||||
else
|
||||
mpDriverData = nullptr;
|
||||
|
@ -96,7 +96,6 @@ ImplJobSetup::ImplJobSetup( const ImplJobSetup& rJobSetup ) :
|
|||
|
||||
ImplJobSetup::~ImplJobSetup()
|
||||
{
|
||||
std::free( mpDriverData );
|
||||
}
|
||||
|
||||
void ImplJobSetup::SetSystem(sal_uInt16 nSystem)
|
||||
|
@ -144,16 +143,12 @@ void ImplJobSetup::SetPaperHeight(tools::Long nPaperHeight)
|
|||
mnPaperHeight = nPaperHeight;
|
||||
}
|
||||
|
||||
void ImplJobSetup::SetDriverDataLen(sal_uInt32 nDriverDataLen)
|
||||
void ImplJobSetup::SetDriverData(std::unique_ptr<sal_uInt8[]> pDriverData, sal_uInt32 nDriverDataLen)
|
||||
{
|
||||
mpDriverData = std::move(pDriverData);
|
||||
mnDriverDataLen = nDriverDataLen;
|
||||
}
|
||||
|
||||
void ImplJobSetup::SetDriverData(sal_uInt8* pDriverData)
|
||||
{
|
||||
mpDriverData = pDriverData;
|
||||
}
|
||||
|
||||
void ImplJobSetup::SetPapersizeFromSetup(bool bPapersizeFromSetup)
|
||||
{
|
||||
mbPapersizeFromSetup = bPapersizeFromSetup;
|
||||
|
@ -187,7 +182,9 @@ bool ImplJobSetup::operator==( const ImplJobSetup& rImplJobSetup ) const
|
|||
mbPapersizeFromSetup == rImplJobSetup.mbPapersizeFromSetup &&
|
||||
mnDriverDataLen == rImplJobSetup.mnDriverDataLen &&
|
||||
maValueMap == rImplJobSetup.maValueMap &&
|
||||
memcmp( mpDriverData, rImplJobSetup.mpDriverData, mnDriverDataLen ) == 0;
|
||||
memcmp( mpDriverData.get(),
|
||||
rImplJobSetup.mpDriverData.get(),
|
||||
std::min(mnDriverDataLen, rImplJobSetup.mnDriverDataLen)) == 0;
|
||||
}
|
||||
|
||||
namespace
|
||||
|
@ -283,7 +280,7 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
|
|||
Impl364JobSetupData* pOldJobData = reinterpret_cast<Impl364JobSetupData*>(pTempBuf.get() + sizeof( ImplOldJobSetupData ));
|
||||
sal_uInt16 nOldJobDataSize = SVBT16ToUInt16( pOldJobData->nSize );
|
||||
rJobData.SetSystem( SVBT16ToUInt16( pOldJobData->nSystem ) );
|
||||
rJobData.SetDriverDataLen( SVBT32ToUInt32( pOldJobData->nDriverDataLen ) );
|
||||
const sal_uInt32 nDriverDataLen = SVBT32ToUInt32( pOldJobData->nDriverDataLen );
|
||||
rJobData.SetOrientation( static_cast<Orientation>(SVBT16ToUInt16( pOldJobData->nOrientation )) );
|
||||
rJobData.SetDuplexMode( DuplexMode::Unknown );
|
||||
rJobData.SetPaperBin( SVBT16ToUInt16( pOldJobData->nPaperBin ) );
|
||||
|
@ -297,7 +294,7 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
|
|||
}
|
||||
rJobData.SetPaperWidth( static_cast<tools::Long>(SVBT32ToUInt32( pOldJobData->nPaperWidth )) );
|
||||
rJobData.SetPaperHeight( static_cast<tools::Long>(SVBT32ToUInt32( pOldJobData->nPaperHeight )) );
|
||||
if ( rJobData.GetDriverDataLen() )
|
||||
if ( nDriverDataLen )
|
||||
{
|
||||
const char* pDriverData = reinterpret_cast<const char*>(pOldJobData) + nOldJobDataSize;
|
||||
const char* pDriverDataEnd = pDriverData + rJobData.GetDriverDataLen();
|
||||
|
@ -307,10 +304,9 @@ SvStream& ReadJobSetup( SvStream& rIStream, JobSetup& rJobSetup )
|
|||
}
|
||||
else
|
||||
{
|
||||
sal_uInt8* pNewDriverData = static_cast<sal_uInt8*>(
|
||||
std::malloc( rJobData.GetDriverDataLen() ));
|
||||
memcpy( pNewDriverData, pDriverData, rJobData.GetDriverDataLen() );
|
||||
rJobData.SetDriverData( pNewDriverData );
|
||||
auto pNewDriverData = std::make_unique<sal_uInt8[]>( nDriverDataLen );
|
||||
memcpy( pNewDriverData.get(), pDriverData, nDriverDataLen );
|
||||
rJobData.SetDriverData( std::move(pNewDriverData), nDriverDataLen );
|
||||
}
|
||||
}
|
||||
if( nSystem == JOBSET_FILE605_SYSTEM )
|
||||
|
|
|
@ -616,9 +616,7 @@ void Printer::ImplInit( SalPrinterQueueInfo* pInfo )
|
|||
if ( rData.GetPrinterName() != pInfo->maPrinterName ||
|
||||
rData.GetDriver() != pInfo->maDriver )
|
||||
{
|
||||
std::free( const_cast<sal_uInt8*>(rData.GetDriverData()) );
|
||||
rData.SetDriverData(nullptr);
|
||||
rData.SetDriverDataLen(0);
|
||||
rData.SetDriverData(nullptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -226,20 +226,16 @@ static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
|
|||
}
|
||||
|
||||
// copy the whole context
|
||||
if( pJobSetup->GetDriverData() )
|
||||
std::free( const_cast<sal_uInt8*>(pJobSetup->GetDriverData()) );
|
||||
|
||||
sal_uInt32 nBytes;
|
||||
void* pBuffer = nullptr;
|
||||
std::unique_ptr<sal_uInt8[]> pBuffer;
|
||||
if( rData.getStreamBuffer( pBuffer, nBytes ) )
|
||||
{
|
||||
pJobSetup->SetDriverDataLen( nBytes );
|
||||
pJobSetup->SetDriverData( static_cast<sal_uInt8*>(pBuffer) );
|
||||
pJobSetup->SetDriverData( std::move(pBuffer), nBytes );
|
||||
}
|
||||
else
|
||||
{
|
||||
pJobSetup->SetDriverDataLen( 0 );
|
||||
pJobSetup->SetDriverData( nullptr );
|
||||
pJobSetup->SetDriverData( nullptr, 0 );
|
||||
}
|
||||
pJobSetup->SetPapersizeFromSetup( rData.m_bPapersizeFromSetup );
|
||||
}
|
||||
|
@ -428,14 +424,12 @@ bool PspSalInfoPrinter::Setup( weld::Window* pFrame, ImplJobSetup* pJobSetup )
|
|||
|
||||
if (SetupPrinterDriver(pFrame, aInfo))
|
||||
{
|
||||
std::free( const_cast<sal_uInt8*>(pJobSetup->GetDriverData()) );
|
||||
pJobSetup->SetDriverData( nullptr );
|
||||
pJobSetup->SetDriverData( nullptr, 0 );
|
||||
|
||||
sal_uInt32 nBytes;
|
||||
void* pBuffer = nullptr;
|
||||
std::unique_ptr<sal_uInt8[]> pBuffer;
|
||||
aInfo.getStreamBuffer( pBuffer, nBytes );
|
||||
pJobSetup->SetDriverDataLen( nBytes );
|
||||
pJobSetup->SetDriverData( static_cast<sal_uInt8*>(pBuffer) );
|
||||
pJobSetup->SetDriverData( std::move(pBuffer), nBytes );
|
||||
|
||||
// copy everything to job setup
|
||||
copyJobDataToJobSetup( pJobSetup, aInfo );
|
||||
|
|
|
@ -87,7 +87,7 @@ void JobData::setPaperBin( int i_nPaperBin )
|
|||
}
|
||||
}
|
||||
|
||||
bool JobData::getStreamBuffer( void*& pData, sal_uInt32& bytes )
|
||||
bool JobData::getStreamBuffer( std::unique_ptr<sal_uInt8[]>& pData, sal_uInt32& bytes )
|
||||
{
|
||||
// consistency checks
|
||||
if( ! m_pParser )
|
||||
|
@ -141,8 +141,8 @@ bool JobData::getStreamBuffer( void*& pData, sal_uInt32& bytes )
|
|||
|
||||
// success
|
||||
bytes = static_cast<sal_uInt32>(aStream.Tell());
|
||||
pData = std::malloc( bytes );
|
||||
memcpy( pData, aStream.GetData(), bytes );
|
||||
pData = std::make_unique<sal_uInt8[]>( bytes );
|
||||
memcpy( pData.get(), aStream.GetData(), bytes );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,9 +317,7 @@ static bool ImplTestSalJobSetup( WinSalInfoPrinter const * pPrinter,
|
|||
}
|
||||
if ( bDelete )
|
||||
{
|
||||
std::free( const_cast<sal_uInt8*>(pSetupData->GetDriverData()) );
|
||||
pSetupData->SetDriverData( nullptr );
|
||||
pSetupData->SetDriverDataLen( 0 );
|
||||
pSetupData->SetDriverData( nullptr, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,6 +338,7 @@ static bool ImplUpdateSalJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe
|
|||
LONG nRet;
|
||||
HWND hWnd = nullptr;
|
||||
DWORD nMode = DM_OUT_BUFFER;
|
||||
std::unique_ptr<sal_uInt8[]> pDriverData;
|
||||
SalDriverData* pOutBuffer = nullptr;
|
||||
BYTE const * pInBuffer = nullptr;
|
||||
|
||||
|
@ -354,7 +353,9 @@ static bool ImplUpdateSalJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe
|
|||
|
||||
// make Outputbuffer
|
||||
const std::size_t nDriverDataLen = sizeof(SalDriverData) + nSysJobSize-1;
|
||||
pOutBuffer = static_cast<SalDriverData*>(rtl_allocateZeroMemory( nDriverDataLen ));
|
||||
pDriverData = std::make_unique<sal_uInt8[]>( nDriverDataLen );
|
||||
memset(pDriverData.get(), 0, nDriverDataLen);
|
||||
pOutBuffer = reinterpret_cast<SalDriverData*>(pDriverData.get());
|
||||
pOutBuffer->mnSysSignature = SAL_DRIVERDATA_SYSSIGN;
|
||||
// calculate driver data offset including structure padding
|
||||
pOutBuffer->mnDriverOffset = sal::static_int_cast<sal_uInt16>(
|
||||
|
@ -390,10 +391,7 @@ static bool ImplUpdateSalJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe
|
|||
ClosePrinter( hPrn );
|
||||
|
||||
if( (nRet < 0) || (pVisibleDlgParent && (nRet == IDCANCEL)) )
|
||||
{
|
||||
std::free( pOutBuffer );
|
||||
return false;
|
||||
}
|
||||
|
||||
// fill up string buffers with 0 so they do not influence a JobSetup's memcmp
|
||||
if( reinterpret_cast<LPDEVMODEW>(pOutDevMode)->dmSize >= 64 )
|
||||
|
@ -410,10 +408,7 @@ static bool ImplUpdateSalJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe
|
|||
}
|
||||
|
||||
// update data
|
||||
if ( pSetupData->GetDriverData() )
|
||||
std::free( const_cast<sal_uInt8*>(pSetupData->GetDriverData()) );
|
||||
pSetupData->SetDriverDataLen( nDriverDataLen );
|
||||
pSetupData->SetDriverData(reinterpret_cast<BYTE*>(pOutBuffer));
|
||||
pSetupData->SetDriverData(std::move(pDriverData), nDriverDataLen);
|
||||
pSetupData->SetSystem( JOBSETUP_SYSTEM_WINDOWS );
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue