Kaydet (Commit) f90e32c0 authored tarafından Noel Grandin's avatar Noel Grandin

tdf#119841 Crash when pasting an HTML table from a web page

regression from
    commit 51003378
    loplugin:useuniqueptr in ScHTMLLayoutParser

Change-Id: If2c46552d8c784eb2ea1b182140fd731c39b1bd3
Reviewed-on: https://gerrit.libreoffice.org/60483
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9237a905
...@@ -218,15 +218,20 @@ ScHTMLLayoutParser::ScHTMLLayoutParser( ...@@ -218,15 +218,20 @@ ScHTMLLayoutParser::ScHTMLLayoutParser(
bInCell( false ), bInCell( false ),
bInTitle( false ) bInTitle( false )
{ {
MakeColNoRef( pLocalColOffset.get(), 0, 0, 0, 0 ); MakeColNoRef( pLocalColOffset, 0, 0, 0, 0 );
MakeColNoRef( &maColOffset, 0, 0, 0, 0 ); MakeColNoRef( &maColOffset, 0, 0, 0, 0 );
} }
ScHTMLLayoutParser::~ScHTMLLayoutParser() ScHTMLLayoutParser::~ScHTMLLayoutParser()
{ {
while ( !aTableStack.empty() ) while ( !aTableStack.empty() )
{
ScHTMLTableStackEntry * pS = aTableStack.top().get();
if ( pS->pLocalColOffset != pLocalColOffset )
delete pS->pLocalColOffset;
aTableStack.pop(); aTableStack.pop();
pLocalColOffset.reset(); }
delete pLocalColOffset;
if ( pTables ) if ( pTables )
{ {
for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it) for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it)
...@@ -639,7 +644,7 @@ void ScHTMLLayoutParser::SetWidths() ...@@ -639,7 +644,7 @@ void ScHTMLLayoutParser::SetWidths()
pLocalColOffset->clear(); pLocalColOffset->clear();
for ( nCol = 0; nCol <= nColsPerRow; ++nCol, nOff = nOff + nWidth ) for ( nCol = 0; nCol <= nColsPerRow; ++nCol, nOff = nOff + nWidth )
{ {
MakeColNoRef( pLocalColOffset.get(), nOff, 0, 0, 0 ); MakeColNoRef( pLocalColOffset, nOff, 0, 0, 0 );
} }
nTableWidth = static_cast<sal_uInt16>(pLocalColOffset->back() - pLocalColOffset->front()); nTableWidth = static_cast<sal_uInt16>(pLocalColOffset->back() - pLocalColOffset->front());
for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i ) for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i )
...@@ -729,7 +734,7 @@ void ScHTMLLayoutParser::SetWidths() ...@@ -729,7 +734,7 @@ void ScHTMLLayoutParser::SetWidths()
pLocalColOffset->clear(); pLocalColOffset->clear();
for ( nCol = 0; nCol <= nColsPerRow; nCol++ ) for ( nCol = 0; nCol <= nColsPerRow; nCol++ )
{ {
MakeColNoRef( pLocalColOffset.get(), pOffsets[nCol], 0, 0, 0 ); MakeColNoRef( pLocalColOffset, pOffsets[nCol], 0, 0, 0 );
} }
nTableWidth = pOffsets[nColsPerRow] - pOffsets[0]; nTableWidth = pOffsets[nColsPerRow] - pOffsets[0];
...@@ -793,7 +798,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE ) ...@@ -793,7 +798,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE )
} }
pE->nOffset = nColOffset; pE->nOffset = nColOffset;
sal_uInt16 nWidth = GetWidth( pE ); sal_uInt16 nWidth = GetWidth( pE );
MakeCol( pLocalColOffset.get(), pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance ); MakeCol( pLocalColOffset, pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance );
if ( pE->nWidth ) if ( pE->nWidth )
pE->nWidth = nWidth; pE->nWidth = nWidth;
nColOffset = pE->nOffset + nWidth; nColOffset = pE->nOffset + nWidth;
...@@ -1026,7 +1031,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1026,7 +1031,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize() sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize()
Colonize(mxActEntry.get()); Colonize(mxActEntry.get());
aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>( aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
mxActEntry, xLockedList, std::move(pLocalColOffset), nFirstTableCell, mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell,
nRowCnt, nColCntStart, nMaxCol, nTable, nRowCnt, nColCntStart, nMaxCol, nTable,
nTableWidth, nColOffset, nColOffsetStart, nTableWidth, nColOffset, nColOffsetStart,
bFirstRow ) ); bFirstRow ) );
...@@ -1082,7 +1087,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1082,7 +1087,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
NextRow( pInfo ); NextRow( pInfo );
} }
aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>( aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
mxActEntry, xLockedList, std::move(pLocalColOffset), nFirstTableCell, mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell,
nRowCnt, nColCntStart, nMaxCol, nTable, nRowCnt, nColCntStart, nMaxCol, nTable,
nTableWidth, nColOffset, nColOffsetStart, nTableWidth, nColOffset, nColOffsetStart,
bFirstRow ) ); bFirstRow ) );
...@@ -1115,8 +1120,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1115,8 +1120,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
bFirstRow = true; bFirstRow = true;
nFirstTableCell = maList.size(); nFirstTableCell = maList.size();
pLocalColOffset.reset( new ScHTMLColOffset ); pLocalColOffset = new ScHTMLColOffset;
MakeColNoRef( pLocalColOffset.get(), nColOffsetStart, 0, 0, 0 ); MakeColNoRef( pLocalColOffset, nColOffsetStart, 0, 0, 0 );
} }
void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
...@@ -1232,7 +1237,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1232,7 +1237,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
{ {
sal_uInt16 nOldOffset = pE->nOffset + pE->nWidth; sal_uInt16 nOldOffset = pE->nOffset + pE->nWidth;
sal_uInt16 nNewOffset = pE->nOffset + nTableWidth; sal_uInt16 nNewOffset = pE->nOffset + nTableWidth;
ModifyOffset( pS->pLocalColOffset.get(), nOldOffset, nNewOffset, nOffsetTolerance ); ModifyOffset( pS->pLocalColOffset, nOldOffset, nNewOffset, nOffsetTolerance );
sal_uInt16 nTmp = nNewOffset - pE->nOffset - pE->nWidth; sal_uInt16 nTmp = nNewOffset - pE->nOffset - pE->nWidth;
pE->nWidth = nNewOffset - pE->nOffset; pE->nWidth = nNewOffset - pE->nOffset;
pS->nTableWidth = pS->nTableWidth + nTmp; pS->nTableWidth = pS->nTableWidth + nTmp;
...@@ -1251,7 +1256,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1251,7 +1256,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
nColOffsetStart = pS->nColOffsetStart; nColOffsetStart = pS->nColOffsetStart;
bFirstRow = pS->bFirstRow; bFirstRow = pS->bFirstRow;
xLockedList = pS->xLockedList; xLockedList = pS->xLockedList;
pLocalColOffset = std::move( pS->pLocalColOffset ); pLocalColOffset = pS->pLocalColOffset;
// mxActEntry is kept around if a table is started in the same row // mxActEntry is kept around if a table is started in the same row
// (anything's possible in HTML); will be deleted by CloseEntry // (anything's possible in HTML); will be deleted by CloseEntry
mxActEntry = pE; mxActEntry = pE;
...@@ -1266,9 +1271,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1266,9 +1271,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
nTable = 0; nTable = 0;
if ( !aTableStack.empty() ) if ( !aTableStack.empty() )
{ {
std::unique_ptr<ScHTMLTableStackEntry> pS = std::move(aTableStack.top()); ScHTMLTableStackEntry* pS = aTableStack.top().get();
delete pLocalColOffset;
pLocalColOffset = pS->pLocalColOffset;
aTableStack.pop(); aTableStack.pop();
pLocalColOffset = std::move( pS->pLocalColOffset );
} }
} }
} }
...@@ -1374,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo ) ...@@ -1374,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo )
if( rOption.GetToken() == HtmlOptionId::WIDTH ) if( rOption.GetToken() == HtmlOptionId::WIDTH )
{ {
sal_uInt16 nVal = GetWidthPixel( rOption ); sal_uInt16 nVal = GetWidthPixel( rOption );
MakeCol( pLocalColOffset.get(), nColOffset, nVal, 0, 0 ); MakeCol( pLocalColOffset, nColOffset, nVal, 0, 0 );
nColOffset = nColOffset + nVal; nColOffset = nColOffset + nVal;
} }
} }
......
...@@ -99,7 +99,7 @@ struct ScHTMLTableStackEntry ...@@ -99,7 +99,7 @@ struct ScHTMLTableStackEntry
{ {
ScRangeListRef xLockedList; ScRangeListRef xLockedList;
std::shared_ptr<ScEEParseEntry> xCellEntry; std::shared_ptr<ScEEParseEntry> xCellEntry;
std::unique_ptr<ScHTMLColOffset> pLocalColOffset; ScHTMLColOffset* pLocalColOffset;
sal_uLong nFirstTableCell; sal_uLong nFirstTableCell;
SCROW nRowCnt; SCROW nRowCnt;
SCCOL nColCntStart; SCCOL nColCntStart;
...@@ -110,14 +110,14 @@ struct ScHTMLTableStackEntry ...@@ -110,14 +110,14 @@ struct ScHTMLTableStackEntry
sal_uInt16 nColOffsetStart; sal_uInt16 nColOffsetStart;
bool bFirstRow; bool bFirstRow;
ScHTMLTableStackEntry( const std::shared_ptr<ScEEParseEntry>& rE, ScHTMLTableStackEntry( const std::shared_ptr<ScEEParseEntry>& rE,
const ScRangeListRef& rL, std::unique_ptr<ScHTMLColOffset> pTO, const ScRangeListRef& rL, ScHTMLColOffset* pTO,
sal_uLong nFTC, sal_uLong nFTC,
SCROW nRow, SCROW nRow,
SCCOL nStart, SCCOL nMax, sal_uInt16 nTab, SCCOL nStart, SCCOL nMax, sal_uInt16 nTab,
sal_uInt16 nTW, sal_uInt16 nCO, sal_uInt16 nCOS, sal_uInt16 nTW, sal_uInt16 nCO, sal_uInt16 nCOS,
bool bFR ) bool bFR )
: xLockedList( rL ), xCellEntry(rE), : xLockedList( rL ), xCellEntry(rE),
pLocalColOffset( std::move(pTO) ), pLocalColOffset( pTO ),
nFirstTableCell( nFTC ), nFirstTableCell( nFTC ),
nRowCnt( nRow ), nRowCnt( nRow ),
nColCntStart( nStart ), nMaxCol( nMax ), nColCntStart( nStart ), nMaxCol( nMax ),
...@@ -158,7 +158,7 @@ private: ...@@ -158,7 +158,7 @@ private:
ScRangeListRef xLockedList; // per table ScRangeListRef xLockedList; // per table
std::unique_ptr<OuterMap> pTables; std::unique_ptr<OuterMap> pTables;
ScHTMLColOffset maColOffset; ScHTMLColOffset maColOffset;
std::unique_ptr<ScHTMLColOffset> pLocalColOffset; // per table ScHTMLColOffset* pLocalColOffset; // per table
sal_uLong nFirstTableCell; // per table sal_uLong nFirstTableCell; // per table
short nTableLevel; short nTableLevel;
sal_uInt16 nTable; sal_uInt16 nTable;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment