summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-09-02 20:05:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-09-04 08:17:06 +0200
commitd4dc6b5cfdb02ad00a06ad32650948648abe010d (patch)
tree02446cd93e68aba9b78db6eb7fc902e782c6faf9 /editeng
parent86fa9c907387e96c9c93f1e17239730271fedbfd (diff)
use std::vector for fetching DX array data
because I'm trying to track down a related heap corruption, and that is much easier if the access to the array is checked by the std::vector debug runtime Change-Id: Ia665f5cebb7f14d88942e88b4b400ad3c28ef5d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121527 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/impedit3.cxx33
-rw-r--r--editeng/source/items/svxfont.cxx6
-rw-r--r--editeng/source/outliner/outliner.cxx6
3 files changed, 19 insertions, 26 deletions
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 8a5d53675d5a..441a3ef65aad 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -753,7 +753,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
ImplInitLayoutMode(*GetRefDevice(), nPara, nIndex);
- std::unique_ptr<tools::Long[]> pBuf(new tools::Long[ pNode->Len() ]);
+ std::vector<tools::Long> aBuf( pNode->Len() );
bool bSameLineAgain = false; // For TextRanger, if the height changes.
TabInfo aCurrentTab;
@@ -1040,9 +1040,8 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
OUString aFieldValue = static_cast<const EditCharAttribField*>(pNextFeature)->GetFieldValue();
// get size, but also DXArray to allow length information in line breaking below
- const sal_Int32 nLength(aFieldValue.getLength());
- std::unique_ptr<tools::Long[]> pTmpDXArray(new tools::Long[nLength]);
- pPortion->GetSize() = aTmpFont.QuickGetTextSize(GetRefDevice(), aFieldValue, 0, aFieldValue.getLength(), pTmpDXArray.get());
+ std::vector<tools::Long> aTmpDXArray;
+ pPortion->GetSize() = aTmpFont.QuickGetTextSize(GetRefDevice(), aFieldValue, 0, aFieldValue.getLength(), &aTmpDXArray);
// So no scrolling for oversized fields
if ( pPortion->GetSize().Width() > nXWidth )
@@ -1086,7 +1085,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
if(a == nNextCellBreak)
{
// check width
- if(pTmpDXArray[a] - nLineStartX > nXWidth)
+ if(aTmpDXArray[a] - nLineStartX > nXWidth)
{
// new CellBreak does not fit in current line, need to
// create a break at LastCellBreak - but do not add 1st
@@ -1097,7 +1096,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
}
// moveLineStart forward in X
- nLineStartX = pTmpDXArray[nLastCellBreak];
+ nLineStartX = aTmpDXArray[nLastCellBreak];
}
// update CellBreak iteration values
@@ -1147,7 +1146,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
if (bContinueLastPortion)
{
Size aSize( aTmpFont.QuickGetTextSize( GetRefDevice(),
- rParaPortion.GetNode()->GetString(), nTmpPos, nPortionLen, pBuf.get() ));
+ rParaPortion.GetNode()->GetString(), nTmpPos, nPortionLen, &aBuf ));
pPortion->GetSize().AdjustWidth(aSize.Width() );
if (pPortion->GetSize().Height() < aSize.Height())
pPortion->GetSize().setHeight( aSize.Height() );
@@ -1155,7 +1154,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
else
{
pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(),
- rParaPortion.GetNode()->GetString(), nTmpPos, nPortionLen, pBuf.get() );
+ rParaPortion.GetNode()->GetString(), nTmpPos, nPortionLen, &aBuf );
}
// #i9050# Do Kerning also behind portions...
@@ -1167,7 +1166,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
// => Always simply quick inserts.
size_t nPos = nTmpPos - pLine->GetStart();
EditLine::CharPosArrayType& rArray = pLine->GetCharPosArray();
- rArray.insert( rArray.begin() + nPos, pBuf.get(), pBuf.get() + nPortionLen);
+ rArray.insert( rArray.begin() + nPos, aBuf.data(), aBuf.data() + nPortionLen);
// And now check for Compression:
if ( !bContinueLastPortion && nPortionLen && GetAsianCompressionMode() != CharCompressType::NONE )
@@ -1650,8 +1649,6 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
if ( bLineBreak )
CreateAndInsertEmptyLine( &rParaPortion );
- pBuf.reset();
-
bool bHeightChanged = FinishCreateLines( &rParaPortion );
if ( bMapChanged )
@@ -3262,7 +3259,7 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
sal_Int32 nTextStart = 0;
sal_Int32 nTextLen = 0;
const tools::Long* pDXArray = nullptr;
- std::unique_ptr<tools::Long[]> pTmpDXArray;
+ std::vector<tools::Long> aTmpDXArray;
if ( rTextPortion.GetKind() == PortionKind::TEXT )
{
@@ -3392,10 +3389,9 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
}
}
- pTmpDXArray.reset(new tools::Long[ aText.getLength() ]);
- pDXArray = pTmpDXArray.get();
aTmpFont.SetPhysFont(*GetRefDevice());
- aTmpFont.QuickGetTextSize( GetRefDevice(), aText, nTextStart, nTextLen, pTmpDXArray.get() );
+ aTmpFont.QuickGetTextSize( GetRefDevice(), aText, nTextStart, nTextLen, &aTmpDXArray );
+ pDXArray = aTmpDXArray.data();
// add a meta file comment if we record to a metafile
if( bMetafileValid )
@@ -3419,10 +3415,9 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
nTextLen = aText.getLength();
// crash when accessing 0 pointer in pDXArray
- pTmpDXArray.reset(new tools::Long[ aText.getLength() ]);
- pDXArray = pTmpDXArray.get();
aTmpFont.SetPhysFont(*GetRefDevice());
- aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.getLength(), pTmpDXArray.get() );
+ aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.getLength(), &aTmpDXArray );
+ pDXArray = aTmpDXArray.data();
}
tools::Long nTxtWidth = rTextPortion.GetSize().Width();
@@ -3681,8 +3676,6 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
rOutDev.Pop();
- pTmpDXArray.reset();
-
if ( rTextPortion.GetKind() == PortionKind::FIELD )
{
// add a meta file comment if we record to a metafile
diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index f92c6851a8f3..691ef6cb037a 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -452,7 +452,7 @@ Size SvxFont::GetPhysTxtSize( const OutputDevice *pOut )
}
Size SvxFont::QuickGetTextSize( const OutputDevice *pOut, const OUString &rTxt,
- const sal_Int32 nIdx, const sal_Int32 nLen, tools::Long* pDXArray ) const
+ const sal_Int32 nIdx, const sal_Int32 nLen, std::vector<tools::Long>* pDXArray ) const
{
if ( !IsCaseMap() && !IsKern() )
return Size( pOut->GetTextArray( rTxt, pDXArray, nIdx, nLen ),
@@ -473,9 +473,9 @@ Size SvxFont::QuickGetTextSize( const OutputDevice *pOut, const OUString &rTxt,
if ( pDXArray )
{
for ( sal_Int32 i = 0; i < nLen; i++ )
- pDXArray[i] += ( (i+1) * tools::Long( nKern ) );
+ (*pDXArray)[i] += ( (i+1) * tools::Long( nKern ) );
// The last one is a nKern too big:
- pDXArray[nLen-1] -= nKern;
+ (*pDXArray)[nLen-1] -= nKern;
}
}
return aTxtSize;
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index c9196a02295f..d23d598e3482 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -975,8 +975,8 @@ void Outliner::PaintBullet(sal_Int32 nPara, const Point& rStartPos, const Point&
if(bStrippingPortions)
{
const vcl::Font& aSvxFont(rOutDev.GetFont());
- std::unique_ptr<tools::Long[]> pBuf(new tools::Long[ pPara->GetText().getLength() ]);
- rOutDev.GetTextArray( pPara->GetText(), pBuf.get() );
+ std::vector<tools::Long> aBuf;
+ rOutDev.GetTextArray( pPara->GetText(), &aBuf );
if(bSymbol)
{
@@ -985,7 +985,7 @@ void Outliner::PaintBullet(sal_Int32 nPara, const Point& rStartPos, const Point&
aTextPos.AdjustY( -(aMetric.GetDescent()) );
}
- DrawingText(aTextPos, pPara->GetText(), 0, pPara->GetText().getLength(), pBuf.get(),
+ DrawingText(aTextPos, pPara->GetText(), 0, pPara->GetText().getLength(), aBuf.data(),
aSvxFont, nPara, bRightToLeftPara ? 1 : 0, nullptr, nullptr, false, false, true, nullptr, Color(), Color());
}
else