From f90e32c06b206390455a1f3bf5c0892ef59ec89d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 14 Sep 2018 11:20:07 +0200 Subject: tdf#119841 Crash when pasting an HTML table from a web page regression from commit 510033783a9921eef507d424fc5adf6e2696bc4a loplugin:useuniqueptr in ScHTMLLayoutParser Change-Id: If2c46552d8c784eb2ea1b182140fd731c39b1bd3 Reviewed-on: https://gerrit.libreoffice.org/60483 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/filter/html/htmlpars.cxx | 34 ++++++++++++++++++++-------------- sc/source/filter/inc/htmlpars.hxx | 8 ++++---- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'sc') diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index eaed6bff3893..401475d9fe0c 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -218,15 +218,20 @@ ScHTMLLayoutParser::ScHTMLLayoutParser( bInCell( false ), bInTitle( false ) { - MakeColNoRef( pLocalColOffset.get(), 0, 0, 0, 0 ); + MakeColNoRef( pLocalColOffset, 0, 0, 0, 0 ); MakeColNoRef( &maColOffset, 0, 0, 0, 0 ); } ScHTMLLayoutParser::~ScHTMLLayoutParser() { while ( !aTableStack.empty() ) + { + ScHTMLTableStackEntry * pS = aTableStack.top().get(); + if ( pS->pLocalColOffset != pLocalColOffset ) + delete pS->pLocalColOffset; aTableStack.pop(); - pLocalColOffset.reset(); + } + delete pLocalColOffset; if ( pTables ) { for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it) @@ -639,7 +644,7 @@ void ScHTMLLayoutParser::SetWidths() pLocalColOffset->clear(); 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(pLocalColOffset->back() - pLocalColOffset->front()); for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i ) @@ -729,7 +734,7 @@ void ScHTMLLayoutParser::SetWidths() pLocalColOffset->clear(); 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]; @@ -793,7 +798,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE ) } pE->nOffset = nColOffset; sal_uInt16 nWidth = GetWidth( pE ); - MakeCol( pLocalColOffset.get(), pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance ); + MakeCol( pLocalColOffset, pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance ); if ( pE->nWidth ) pE->nWidth = nWidth; nColOffset = pE->nOffset + nWidth; @@ -1026,7 +1031,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize() Colonize(mxActEntry.get()); aTableStack.push( o3tl::make_unique( - mxActEntry, xLockedList, std::move(pLocalColOffset), nFirstTableCell, + mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell, nRowCnt, nColCntStart, nMaxCol, nTable, nTableWidth, nColOffset, nColOffsetStart, bFirstRow ) ); @@ -1082,7 +1087,7 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) NextRow( pInfo ); } aTableStack.push( o3tl::make_unique( - mxActEntry, xLockedList, std::move(pLocalColOffset), nFirstTableCell, + mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell, nRowCnt, nColCntStart, nMaxCol, nTable, nTableWidth, nColOffset, nColOffsetStart, bFirstRow ) ); @@ -1115,8 +1120,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) bFirstRow = true; nFirstTableCell = maList.size(); - pLocalColOffset.reset( new ScHTMLColOffset ); - MakeColNoRef( pLocalColOffset.get(), nColOffsetStart, 0, 0, 0 ); + pLocalColOffset = new ScHTMLColOffset; + MakeColNoRef( pLocalColOffset, nColOffsetStart, 0, 0, 0 ); } 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 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; pE->nWidth = nNewOffset - pE->nOffset; pS->nTableWidth = pS->nTableWidth + nTmp; @@ -1251,7 +1256,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) nColOffsetStart = pS->nColOffsetStart; bFirstRow = pS->bFirstRow; xLockedList = pS->xLockedList; - pLocalColOffset = std::move( pS->pLocalColOffset ); + pLocalColOffset = pS->pLocalColOffset; // mxActEntry is kept around if a table is started in the same row // (anything's possible in HTML); will be deleted by CloseEntry mxActEntry = pE; @@ -1266,9 +1271,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) nTable = 0; if ( !aTableStack.empty() ) { - std::unique_ptr pS = std::move(aTableStack.top()); + ScHTMLTableStackEntry* pS = aTableStack.top().get(); + delete pLocalColOffset; + pLocalColOffset = pS->pLocalColOffset; aTableStack.pop(); - pLocalColOffset = std::move( pS->pLocalColOffset ); } } } @@ -1374,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo ) if( rOption.GetToken() == HtmlOptionId::WIDTH ) { sal_uInt16 nVal = GetWidthPixel( rOption ); - MakeCol( pLocalColOffset.get(), nColOffset, nVal, 0, 0 ); + MakeCol( pLocalColOffset, nColOffset, nVal, 0, 0 ); nColOffset = nColOffset + nVal; } } diff --git a/sc/source/filter/inc/htmlpars.hxx b/sc/source/filter/inc/htmlpars.hxx index 2518e68631d2..8a1d26a89e2d 100644 --- a/sc/source/filter/inc/htmlpars.hxx +++ b/sc/source/filter/inc/htmlpars.hxx @@ -99,7 +99,7 @@ struct ScHTMLTableStackEntry { ScRangeListRef xLockedList; std::shared_ptr xCellEntry; - std::unique_ptr pLocalColOffset; + ScHTMLColOffset* pLocalColOffset; sal_uLong nFirstTableCell; SCROW nRowCnt; SCCOL nColCntStart; @@ -110,14 +110,14 @@ struct ScHTMLTableStackEntry sal_uInt16 nColOffsetStart; bool bFirstRow; ScHTMLTableStackEntry( const std::shared_ptr& rE, - const ScRangeListRef& rL, std::unique_ptr pTO, + const ScRangeListRef& rL, ScHTMLColOffset* pTO, sal_uLong nFTC, SCROW nRow, SCCOL nStart, SCCOL nMax, sal_uInt16 nTab, sal_uInt16 nTW, sal_uInt16 nCO, sal_uInt16 nCOS, bool bFR ) : xLockedList( rL ), xCellEntry(rE), - pLocalColOffset( std::move(pTO) ), + pLocalColOffset( pTO ), nFirstTableCell( nFTC ), nRowCnt( nRow ), nColCntStart( nStart ), nMaxCol( nMax ), @@ -158,7 +158,7 @@ private: ScRangeListRef xLockedList; // per table std::unique_ptr pTables; ScHTMLColOffset maColOffset; - std::unique_ptr pLocalColOffset; // per table + ScHTMLColOffset* pLocalColOffset; // per table sal_uLong nFirstTableCell; // per table short nTableLevel; sal_uInt16 nTable; -- cgit