vcl/win/gdi/salprn.cxx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
New commits: commit a08fbb2efc884a5e053be0568304751aac39bb07 Author: Mike Kaganski <[email protected]> AuthorDate: Wed Feb 11 14:33:37 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Feb 12 18:45:29 2026 +0100 Don't reinterpret_cast to a random pointer type; use void* Simplifies the code quite a bit. Change-Id: I22c9f218fd6971a257642f796a76b38be4bd286b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199281 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx index c475b315be87..8fa2a2adb16f 100644 --- a/vcl/win/gdi/salprn.cxx +++ b/vcl/win/gdi/salprn.cxx @@ -232,7 +232,7 @@ OUString WinSalInstance::GetDefaultPrinter() } static DWORD ImplDeviceCaps( WinSalInfoPrinter const * pPrinter, WORD nCaps, - BYTE* pOutput, const ImplJobSetup* pSetupData ) + void* pOutput, const ImplJobSetup* pSetupData ) { DEVMODEW const * pDevMode; if ( !pSetupData || !pSetupData->GetDriverData() ) @@ -242,7 +242,7 @@ static DWORD ImplDeviceCaps( WinSalInfoPrinter const * pPrinter, WORD nCaps, return DeviceCapabilitiesW( o3tl::toW(pPrinter->maDeviceName.getStr()), o3tl::toW(pPrinter->maPortName.getStr()), - nCaps, reinterpret_cast<LPWSTR>(pOutput), pDevMode ); + nCaps, static_cast<LPWSTR>(pOutput), pDevMode ); } static bool ImplTestSalJobSetup( WinSalInfoPrinter const * pPrinter, @@ -442,7 +442,7 @@ static void ImplDevModeToJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe if ( nCount && (nCount != GDI_ERROR) ) { WORD* pBins = static_cast<WORD*>(rtl_allocateZeroMemory( nCount*sizeof(WORD) )); - ImplDeviceCaps( pPrinter, DC_BINS, reinterpret_cast<BYTE*>(pBins), pSetupData ); + ImplDeviceCaps( pPrinter, DC_BINS, pBins, pSetupData ); pSetupData->SetPaperBin( 0 ); // search the right bin and assign index to mnPaperBin @@ -476,12 +476,12 @@ static void ImplDevModeToJobSetup( WinSalInfoPrinter const * pPrinter, ImplJobSe if ( nPaperCount && (nPaperCount != GDI_ERROR) ) { pPapers = static_cast<WORD*>(rtl_allocateZeroMemory(nPaperCount*sizeof(WORD))); - ImplDeviceCaps( pPrinter, DC_PAPERS, reinterpret_cast<BYTE*>(pPapers), pSetupData ); + ImplDeviceCaps( pPrinter, DC_PAPERS, pPapers, pSetupData ); } if ( nPaperSizeCount && (nPaperSizeCount != GDI_ERROR) ) { pPaperSizes = static_cast<POINT*>(rtl_allocateZeroMemory(nPaperSizeCount*sizeof(POINT))); - ImplDeviceCaps( pPrinter, DC_PAPERSIZE, reinterpret_cast<BYTE*>(pPaperSizes), pSetupData ); + ImplDeviceCaps( pPrinter, DC_PAPERSIZE, pPaperSizes, pSetupData ); } if( nPaperSizeCount == nPaperCount && pPaperSizes && pPapers ) { @@ -711,7 +711,7 @@ static void ImplJobSetupToDevMode( WinSalInfoPrinter const * pPrinter, const Imp if ( nCount && (nCount != GDI_ERROR) ) { WORD* pBins = static_cast<WORD*>(rtl_allocateZeroMemory(nCount*sizeof(WORD))); - ImplDeviceCaps( pPrinter, DC_BINS, reinterpret_cast<BYTE*>(pBins), pSetupData ); + ImplDeviceCaps( pPrinter, DC_BINS, pBins, pSetupData ); pDevModeW->dmFields |= DM_DEFAULTSOURCE; pDevModeW->dmDefaultSource = pBins[ pSetupData->GetPaperBin() ]; std::free( pBins ); @@ -889,12 +889,12 @@ static void ImplJobSetupToDevMode( WinSalInfoPrinter const * pPrinter, const Imp if ( nPaperCount && (nPaperCount != GDI_ERROR) ) { pPapers = static_cast<WORD*>(rtl_allocateZeroMemory(nPaperCount*sizeof(WORD))); - ImplDeviceCaps( pPrinter, DC_PAPERS, reinterpret_cast<BYTE*>(pPapers), pSetupData ); + ImplDeviceCaps( pPrinter, DC_PAPERS, pPapers, pSetupData ); } if ( nPaperSizeCount && (nPaperSizeCount != GDI_ERROR) ) { pPaperSizes = static_cast<POINT*>(rtl_allocateZeroMemory(nPaperSizeCount*sizeof(POINT))); - ImplDeviceCaps( pPrinter, DC_PAPERSIZE, reinterpret_cast<BYTE*>(pPaperSizes), pSetupData ); + ImplDeviceCaps( pPrinter, DC_PAPERSIZE, pPaperSizes, pSetupData ); } if ( (nPaperSizeCount == nPaperCount) && pPapers && pPaperSizes ) { @@ -1096,7 +1096,7 @@ void WinSalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData ) if( nCount ) { POINT* pPaperSizes = static_cast<POINT*>(rtl_allocateZeroMemory(nCount*sizeof(POINT))); - ImplDeviceCaps( this, DC_PAPERSIZE, reinterpret_cast<BYTE*>(pPaperSizes), pSetupData ); + ImplDeviceCaps( this, DC_PAPERSIZE, pPaperSizes, pSetupData ); SAL_INFO("vcl.print", "DC_PAPERSIZE sizes (mm) from printer: " << DC_PAPERSIZE_array_to_string(pPaperSizes, nCount)); @@ -1186,7 +1186,7 @@ OUString WinSalInfoPrinter::GetPaperBinName( const ImplJobSetup* pSetupData, sal if ( (nPaperBin < nBins) && (nBins != GDI_ERROR) ) { auto pBuffer = std::make_unique<sal_Unicode[]>(nBins*24); - DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, reinterpret_cast<BYTE*>(pBuffer.get()), pSetupData ); + DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, pBuffer.get(), pSetupData ); if ( nRet && (nRet != GDI_ERROR) ) aPaperBinName = OUString( pBuffer.get() + (nPaperBin*24) ); } @@ -1201,7 +1201,7 @@ sal_uInt16 WinSalInfoPrinter::GetPaperBinBySourceIndex( const ImplJobSetup* pSet return 0xffff; auto pBuffer = std::make_unique<sal_uInt16[]>(nBins); - nBins = ImplDeviceCaps( this, DC_BINS, reinterpret_cast<BYTE*>(pBuffer.get()), pSetupData ); + nBins = ImplDeviceCaps( this, DC_BINS, pBuffer.get(), pSetupData ); if (nBins != GDI_ERROR) { for (DWORD nBin = 0; nBin < nBins; ++nBin) @@ -1220,7 +1220,7 @@ sal_uInt16 WinSalInfoPrinter::GetSourceIndexByPaperBin(const ImplJobSetup* pSet return 0; auto pBuffer = std::make_unique<sal_uInt16[]>(nBins); - nBins = ImplDeviceCaps( this, DC_BINS, reinterpret_cast<BYTE*>(pBuffer.get()), pSetupData ); + nBins = ImplDeviceCaps( this, DC_BINS, pBuffer.get(), pSetupData ); if (nBins != GDI_ERROR && nBins > nPaperBin) { return *(pBuffer.get() + nPaperBin); commit b10091783e95c70ddd30aefba0d1e4420521a4cd Author: Mike Kaganski <[email protected]> AuthorDate: Wed Feb 11 14:35:05 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Feb 12 18:45:20 2026 +0100 Drop unused code The result of this call to ImplDeviceCaps was not used. Change-Id: I0c0a5e232100fd9cbd03fbacdec05eafadf58208 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199280 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx index 0a7926fbcdb8..c475b315be87 100644 --- a/vcl/win/gdi/salprn.cxx +++ b/vcl/win/gdi/salprn.cxx @@ -1098,9 +1098,6 @@ void WinSalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData ) POINT* pPaperSizes = static_cast<POINT*>(rtl_allocateZeroMemory(nCount*sizeof(POINT))); ImplDeviceCaps( this, DC_PAPERSIZE, reinterpret_cast<BYTE*>(pPaperSizes), pSetupData ); - sal_Unicode* pNamesBuffer = static_cast<sal_Unicode*>(std::malloc(nCount*64*sizeof(sal_Unicode))); - ImplDeviceCaps( this, DC_PAPERNAMES, reinterpret_cast<BYTE*>(pNamesBuffer), pSetupData ); - SAL_INFO("vcl.print", "DC_PAPERSIZE sizes (mm) from printer: " << DC_PAPERSIZE_array_to_string(pPaperSizes, nCount)); for( DWORD i = 0; i < nCount; ++i ) @@ -1108,7 +1105,6 @@ void WinSalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData ) PaperInfo aInfo(pPaperSizes[i].x * 10, pPaperSizes[i].y * 10); m_aPaperFormats.push_back( aInfo ); } - std::free( pNamesBuffer ); std::free( pPaperSizes ); }
