diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-28 09:27:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-29 12:38:51 +0200 |
commit | 894b4911ffb96ff667fdeb3aec7922316ab7230a (patch) | |
tree | 3942ed8088c058b70bb79984b186c5156284abf4 /vcl/source/filter | |
parent | 5b0ae3b59cd2cccfb72d991657366eb2a69bff49 (diff) |
pass DX array around using o3tl::span instead of pointer
so we get bounds checking in debug mode
Note that I cannot just pass around the std::vectors
involved because there is a place in editeng which
calls with a subset of a vector.
Change-Id: I5088a139593c27bf9cbe5d843ab4b0048ac6d508
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124330
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/filter')
-rw-r--r-- | vcl/source/filter/eps/eps.cxx | 18 | ||||
-rw-r--r-- | vcl/source/filter/svm/SvmConverter.cxx | 12 | ||||
-rw-r--r-- | vcl/source/filter/svm/SvmReader.cxx | 14 | ||||
-rw-r--r-- | vcl/source/filter/svm/SvmWriter.cxx | 6 | ||||
-rw-r--r-- | vcl/source/filter/wmf/emfwr.cxx | 25 | ||||
-rw-r--r-- | vcl/source/filter/wmf/emfwr.hxx | 2 | ||||
-rw-r--r-- | vcl/source/filter/wmf/wmfwr.cxx | 22 | ||||
-rw-r--r-- | vcl/source/filter/wmf/wmfwr.hxx | 6 |
8 files changed, 57 insertions, 48 deletions
diff --git a/vcl/source/filter/eps/eps.cxx b/vcl/source/filter/eps/eps.cxx index 74a746154397..6da05bb24fb7 100644 --- a/vcl/source/filter/eps/eps.cxx +++ b/vcl/source/filter/eps/eps.cxx @@ -200,10 +200,10 @@ private: void ImplSetClipRegion( vcl::Region const & rRegion ); void ImplBmp( Bitmap const *, Bitmap const *, const Point &, double nWidth, double nHeight ); - void ImplText( const OUString& rUniString, const Point& rPos, const tools::Long* pDXArry, sal_Int32 nWidth, VirtualDevice const & rVDev ); + void ImplText( const OUString& rUniString, const Point& rPos, o3tl::span<const tools::Long> pDXArry, sal_Int32 nWidth, VirtualDevice const & rVDev ); void ImplSetAttrForText( const Point & rPoint ); void ImplWriteCharacter( char ); - void ImplWriteString( const OString&, VirtualDevice const & rVDev, const tools::Long* pDXArry, bool bStretch ); + void ImplWriteString( const OString&, VirtualDevice const & rVDev, o3tl::span<const tools::Long> pDXArry, bool bStretch ); void ImplDefineFont( const char*, const char* ); void ImplClosePathDraw(); @@ -742,7 +742,7 @@ void PSWriter::ImplWriteActions( const GDIMetaFile& rMtf, VirtualDevice& rVDev ) OUString aUniStr = pA->GetText().copy( pA->GetIndex(), pA->GetLen() ); Point aPoint( pA->GetPoint() ); - ImplText( aUniStr, aPoint, nullptr, 0, rVDev ); + ImplText( aUniStr, aPoint, {}, 0, rVDev ); } break; @@ -758,7 +758,7 @@ void PSWriter::ImplWriteActions( const GDIMetaFile& rMtf, VirtualDevice& rVDev ) OUString aUniStr = pA->GetText().copy( pA->GetIndex(), pA->GetLen() ); Point aPoint( pA->GetPoint() ); - ImplText( aUniStr, aPoint, nullptr, pA->GetWidth(), rVDev ); + ImplText( aUniStr, aPoint, {}, pA->GetWidth(), rVDev ); } break; @@ -768,7 +768,7 @@ void PSWriter::ImplWriteActions( const GDIMetaFile& rMtf, VirtualDevice& rVDev ) OUString aUniStr = pA->GetText().copy( pA->GetIndex(), pA->GetLen() ); Point aPoint( pA->GetPoint() ); - ImplText( aUniStr, aPoint, pA->GetDXArray(), 0, rVDev ); + ImplText( aUniStr, aPoint, { pA->GetDXArray().data(), pA->GetDXArray().size() }, 0, rVDev ); } break; @@ -1951,13 +1951,13 @@ void PSWriter::ImplWriteCharacter( char nChar ) ImplWriteByte( static_cast<sal_uInt8>(nChar), PS_NONE ); } -void PSWriter::ImplWriteString( const OString& rString, VirtualDevice const & rVDev, const tools::Long* pDXArry, bool bStretch ) +void PSWriter::ImplWriteString( const OString& rString, VirtualDevice const & rVDev, o3tl::span<const tools::Long> pDXArry, bool bStretch ) { sal_Int32 nLen = rString.getLength(); if ( !nLen ) return; - if ( pDXArry ) + if ( !pDXArry.empty() ) { double nx = 0; @@ -1981,7 +1981,7 @@ void PSWriter::ImplWriteString( const OString& rString, VirtualDevice const & rV } } -void PSWriter::ImplText( const OUString& rUniString, const Point& rPos, const tools::Long* pDXArry, sal_Int32 nWidth, VirtualDevice const & rVDev ) +void PSWriter::ImplText( const OUString& rUniString, const Point& rPos, o3tl::span<const tools::Long> pDXArry, sal_Int32 nWidth, VirtualDevice const & rVDev ) { if ( rUniString.isEmpty() ) return; @@ -2029,7 +2029,7 @@ void PSWriter::ImplText( const OUString& rUniString, const Point& rPos, const to else if ( ( mnTextMode == 1 ) || ( mnTextMode == 2 ) ) // normal text output { if ( mnTextMode == 2 ) // forcing output one complete text packet, by - pDXArry = nullptr; // ignoring the kerning array + pDXArry = {}; // ignoring the kerning array ImplSetAttrForText( rPos ); OString aStr(OUStringToOString(rUniString, maFont.GetCharSet())); diff --git a/vcl/source/filter/svm/SvmConverter.cxx b/vcl/source/filter/svm/SvmConverter.cxx index 40ed636dd011..71c400fb37f3 100644 --- a/vcl/source/filter/svm/SvmConverter.cxx +++ b/vcl/source/filter/svm/SvmConverter.cxx @@ -715,7 +715,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf ) OUString aStr(OStringToOUString(aByteStr, eActualCharSet)); - std::unique_ptr<tools::Long[]> pDXAry; + std::vector<tools::Long> aDXAry; if (nAryLen > 0) { const size_t nMinRecordSize = sizeof(sal_Int32); @@ -742,12 +742,12 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf ) } else { - pDXAry.reset(new tools::Long[nDXAryLen]); + aDXAry.resize(nDXAryLen); for (sal_Int32 j = 0; j < nAryLen; ++j) { rIStm.ReadInt32( nTmp ); - pDXAry[ j ] = nTmp; + aDXAry[ j ] = nTmp; } // #106172# Add last DX array elem, if missing @@ -767,9 +767,9 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf ) // difference to last elem and store // in very last. if( nStrLen > 1 ) - pDXAry[ nStrLen-1 ] = pDXAry[ nStrLen-2 ] + aTmpAry[ nStrLen-1 ] - aTmpAry[ nStrLen-2 ]; + aDXAry[ nStrLen-1 ] = aDXAry[ nStrLen-2 ] + aTmpAry[ nStrLen-1 ] - aTmpAry[ nStrLen-2 ]; else - pDXAry[ nStrLen-1 ] = aTmpAry[ nStrLen-1 ]; // len=1: 0th position taken to be 0 + aDXAry[ nStrLen-1 ] = aTmpAry[ nStrLen-1 ]; // len=1: 0th position taken to be 0 } #ifdef DBG_UTIL else @@ -780,7 +780,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf ) } if ( nUnicodeCommentActionNumber == i ) ImplReadUnicodeComment( nUnicodeCommentStreamPos, rIStm, aStr ); - rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, pDXAry.get(), nIndex, nLen ) ); + rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, aDXAry, nIndex, nLen ) ); } if (nActionSize < 24) diff --git a/vcl/source/filter/svm/SvmReader.cxx b/vcl/source/filter/svm/SvmReader.cxx index 31636fa23362..0f6c19ed0a31 100644 --- a/vcl/source/filter/svm/SvmReader.cxx +++ b/vcl/source/filter/svm/SvmReader.cxx @@ -683,7 +683,7 @@ rtl::Reference<MetaAction> SvmReader::TextArrayHandler(const ImplMetaReadData* p { rtl::Reference<MetaTextArrayAction> pAction(new MetaTextArrayAction); - std::unique_ptr<tools::Long[]> aArray; + std::vector<tools::Long> aArray; VersionCompatRead aCompat(mrStream); TypeSerializer aSerializer(mrStream); @@ -720,9 +720,9 @@ rtl::Reference<MetaAction> SvmReader::TextArrayHandler(const ImplMetaReadData* p // #i9762#, #106172# Ensure that DX array is at least mnLen entries long if (nTmpLen >= nAryLen) { - aArray.reset(new (std::nothrow) tools::Long[nTmpLen]); - if (aArray) + try { + aArray.resize(nTmpLen); sal_Int32 i; sal_Int32 val(0); for (i = 0; i < nAryLen; i++) @@ -734,6 +734,9 @@ rtl::Reference<MetaAction> SvmReader::TextArrayHandler(const ImplMetaReadData* p for (; i < nTmpLen; i++) aArray[i] = 0; } + catch (std::bad_alloc&) + { + } } else { @@ -751,11 +754,12 @@ rtl::Reference<MetaAction> SvmReader::TextArrayHandler(const ImplMetaReadData* p SAL_WARN("vcl.gdi", "inconsistent offset and len"); pAction->SetIndex(0); pAction->SetLen(aStr.getLength()); - aArray.reset(); + aArray.clear(); } } - pAction->SetDXArray(std::move(aArray)); + if (!aArray.empty()) + pAction->SetDXArray(std::move(aArray)); return pAction; } diff --git a/vcl/source/filter/svm/SvmWriter.cxx b/vcl/source/filter/svm/SvmWriter.cxx index f18fc7d624a4..bcc15c5806e4 100644 --- a/vcl/source/filter/svm/SvmWriter.cxx +++ b/vcl/source/filter/svm/SvmWriter.cxx @@ -984,9 +984,9 @@ void SvmWriter::TextArrayHandler(const MetaTextArrayAction* pAction, const ImplM { mrStream.WriteUInt16(static_cast<sal_uInt16>(pAction->GetType())); - tools::Long* aArray = pAction->GetDXArray(); + const std::vector<tools::Long>& rDXArray = pAction->GetDXArray(); - const sal_Int32 nAryLen = aArray ? pAction->GetLen() : 0; + const sal_Int32 nAryLen = !rDXArray.empty() ? pAction->GetLen() : 0; VersionCompatWrite aCompat(mrStream, 2); TypeSerializer aSerializer(mrStream); @@ -997,7 +997,7 @@ void SvmWriter::TextArrayHandler(const MetaTextArrayAction* pAction, const ImplM mrStream.WriteInt32(nAryLen); for (sal_Int32 i = 0; i < nAryLen; ++i) - mrStream.WriteInt32(aArray[i]); + mrStream.WriteInt32(rDXArray[i]); write_uInt16_lenPrefixed_uInt16s_FromOUString(mrStream, pAction->GetText()); // version 2 } diff --git a/vcl/source/filter/wmf/emfwr.cxx b/vcl/source/filter/wmf/emfwr.cxx index 33d41da4ad0d..d9f41fd81fed 100644 --- a/vcl/source/filter/wmf/emfwr.cxx +++ b/vcl/source/filter/wmf/emfwr.cxx @@ -861,7 +861,7 @@ void EMFWriter::ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, } -void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString& rText, const tools::Long* pDXArray, sal_uInt32 nWidth ) +void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString& rText, o3tl::span<const tools::Long> pDXArray, sal_uInt32 nWidth ) { sal_Int32 nLen = rText.getLength(), i; @@ -870,18 +870,18 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString& rText, c sal_uInt32 nNormWidth; std::vector<tools::Long> aOwnArray; - tools::Long* pDX; + o3tl::span<const tools::Long> pDX; // get text sizes - if( pDXArray ) + if( !pDXArray.empty() ) { nNormWidth = maVDev->GetTextWidth( rText ); - pDX = const_cast<tools::Long*>(pDXArray); + pDX = pDXArray; } else { nNormWidth = maVDev->GetTextArray( rText, &aOwnArray ); - pDX = aOwnArray.data(); + pDX = { aOwnArray.data(), aOwnArray.size() }; } if( nLen > 1 ) @@ -890,10 +890,15 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString& rText, c if( nWidth && nNormWidth && ( nWidth != nNormWidth ) ) { + if (!pDXArray.empty()) + { + aOwnArray.insert(aOwnArray.begin(), pDXArray.begin(), pDXArray.end()); + pDX = { aOwnArray.data(), aOwnArray.size() }; + } const double fFactor = static_cast<double>(nWidth) / nNormWidth; for( i = 0; i < ( nLen - 1 ); i++ ) - pDX[ i ] = FRound( pDX[ i ] * fFactor ); + aOwnArray[ i ] = FRound( aOwnArray[ i ] * fFactor ); } } @@ -1346,7 +1351,7 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) const OUString aText = pA->GetText().copy( pA->GetIndex(), std::min(pA->GetText().getLength() - pA->GetIndex(), pA->GetLen()) ); ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, nullptr, 0 ); + ImplWriteTextRecord( pA->GetPoint(), aText, {}, 0 ); } break; @@ -1356,7 +1361,7 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) const OUString& aText( pA->GetText() ); ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetRect().TopLeft(), aText, nullptr, 0 ); + ImplWriteTextRecord( pA->GetRect().TopLeft(), aText, {}, 0 ); } break; @@ -1366,7 +1371,7 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) const OUString aText = pA->GetText().copy( pA->GetIndex(), std::min(pA->GetText().getLength() - pA->GetIndex(), pA->GetLen()) ); ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, pA->GetDXArray(), 0 ); + ImplWriteTextRecord( pA->GetPoint(), aText, { pA->GetDXArray().data(), pA->GetDXArray().size() }, 0 ); } break; @@ -1376,7 +1381,7 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) const OUString aText = pA->GetText().copy( pA->GetIndex(), std::min(pA->GetText().getLength() - pA->GetIndex(), pA->GetLen()) ); ImplCheckTextAttr(); - ImplWriteTextRecord( pA->GetPoint(), aText, nullptr, pA->GetWidth() ); + ImplWriteTextRecord( pA->GetPoint(), aText, {}, pA->GetWidth() ); } break; diff --git a/vcl/source/filter/wmf/emfwr.hxx b/vcl/source/filter/wmf/emfwr.hxx index 31149b976db1..d2d3d9845931 100644 --- a/vcl/source/filter/wmf/emfwr.hxx +++ b/vcl/source/filter/wmf/emfwr.hxx @@ -75,7 +75,7 @@ private: void ImplWritePolygonRecord( const tools::Polygon& rPoly, bool bClose ); void ImplWritePolyPolygonRecord( const tools::PolyPolygon& rPolyPoly ); void ImplWriteBmpRecord( const Bitmap& rBmp, const Point& rPt, const Size& rSz, sal_uInt32 nROP ); - void ImplWriteTextRecord( const Point& rPos, const OUString& rText, const tools::Long* pDXArray, sal_uInt32 nWidth ); + void ImplWriteTextRecord( const Point& rPos, const OUString& rText, o3tl::span<const tools::Long> pDXArray, sal_uInt32 nWidth ); void Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon); void ImplWrite( const GDIMetaFile& rMtf ); diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx index 93bc6e29ee07..b58a25408523 100644 --- a/vcl/source/filter/wmf/wmfwr.cxx +++ b/vcl/source/filter/wmf/wmfwr.cxx @@ -442,7 +442,7 @@ void WMFWriter::WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_In /* if return value is true, then a complete unicode string and also a polygon replacement has been written, so there is no more action necessary */ -bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& rUniStr, const tools::Long* pDXAry ) +bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& rUniStr, o3tl::span<const tools::Long> pDXAry ) { bool bEscapeUsed = false; @@ -509,7 +509,7 @@ bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& r std::vector<tools::PolyPolygon> aPolyPolyVec; if ( pVirDev->GetTextOutlines( aPolyPolyVec, rUniStr ) ) { - sal_uInt32 nDXCount = pDXAry ? nStringLen : 0; + sal_uInt32 nDXCount = !pDXAry.empty() ? nStringLen : 0; sal_uInt32 nSkipActions = aPolyPolyVec.size(); sal_Int32 nStrmLen = 8 + + sizeof( nStringLen ) + ( nStringLen * 2 ) @@ -547,11 +547,11 @@ bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& r void WMFWriter::WMFRecord_ExtTextOut( const Point& rPoint, const OUString& rString, - const tools::Long* pDXAry ) + o3tl::span<const tools::Long> pDXAry ) { sal_Int32 nOriginalTextLen = rString.getLength(); - if ( (nOriginalTextLen <= 1) || (pDXAry == nullptr) ) + if ( (nOriginalTextLen <= 1) || pDXAry.empty() ) { WMFRecord_TextOut(rPoint, rString); return; @@ -562,7 +562,7 @@ void WMFWriter::WMFRecord_ExtTextOut( const Point& rPoint, } void WMFWriter::TrueExtTextOut( const Point& rPoint, const OUString& rString, - const OString& rByteString, const tools::Long* pDXAry ) + const OString& rByteString, o3tl::span<const tools::Long> pDXAry ) { WriteRecordHeader( 0, W_META_EXTTEXTOUT ); WritePointYX( rPoint ); @@ -1162,7 +1162,7 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) SetAllAttr(); Point aPos( pA->GetRect().TopLeft() ); - if ( !WMFRecord_Escape_Unicode( aPos, aTemp, nullptr ) ) + if ( !WMFRecord_Escape_Unicode( aPos, aTemp, {} ) ) WMFRecord_TextOut( aPos, aTemp ); } break; @@ -1173,7 +1173,7 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) OUString aTemp = pA->GetText().copy( pA->GetIndex(), std::min<sal_Int32>(pA->GetText().getLength() - pA->GetIndex(), pA->GetLen()) ); aSrcLineInfo = LineInfo(); SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, nullptr ) ) + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, {} ) ) WMFRecord_TextOut( pA->GetPoint(), aTemp ); } break; @@ -1185,8 +1185,8 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) OUString aTemp = pA->GetText().copy( pA->GetIndex(), std::min<sal_Int32>(pA->GetText().getLength() - pA->GetIndex(), pA->GetLen()) ); aSrcLineInfo = LineInfo(); SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pA->GetDXArray() ) ) - WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pA->GetDXArray() ); + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, { pA->GetDXArray().data(), pA->GetDXArray().size() } ) ) + WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, { pA->GetDXArray().data(), pA->GetDXArray().size() } ); } break; @@ -1211,8 +1211,8 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) aDXAry.clear(); aSrcLineInfo = LineInfo(); SetAllAttr(); - if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, aDXAry.empty() ? nullptr : aDXAry.data() ) ) - WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, aDXAry.empty() ? nullptr : aDXAry.data() ); + if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, { aDXAry.data(), aDXAry.size() } ) ) + WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, { aDXAry.data(), aDXAry.size() } ); } } break; diff --git a/vcl/source/filter/wmf/wmfwr.hxx b/vcl/source/filter/wmf/wmfwr.hxx index 7be7e0bb3e7e..a0961e63a15c 100644 --- a/vcl/source/filter/wmf/wmfwr.hxx +++ b/vcl/source/filter/wmf/wmfwr.hxx @@ -142,11 +142,11 @@ private: void WMFRecord_DeleteObject(sal_uInt16 nObjectHandle); void WMFRecord_Ellipse(const tools::Rectangle& rRect); void WMFRecord_Escape( sal_uInt32 nEsc, sal_uInt32 nLen, const sal_Int8* pData ); - bool WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& rStr, const tools::Long* pDXAry ); - void WMFRecord_ExtTextOut(const Point& rPoint, const OUString& rString, const tools::Long* pDXAry); + bool WMFRecord_Escape_Unicode( const Point& rPoint, const OUString& rStr, o3tl::span<const tools::Long> pDXAry ); + void WMFRecord_ExtTextOut(const Point& rPoint, const OUString& rString, o3tl::span<const tools::Long> pDXAry); void TrueExtTextOut(const Point& rPoint, const OUString& rString, - const OString& rByteString, const tools::Long* pDXAry); + const OString& rByteString, o3tl::span<const tools::Long> pDXAry); void TrueTextOut(const Point& rPoint, const OString& rString); void WMFRecord_LineTo(const Point & rPoint); void WMFRecord_MoveTo(const Point & rPoint); |