summaryrefslogtreecommitdiff
path: root/sw/source/filter/html/htmltab.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-12-14 13:10:26 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-12-16 16:51:14 +0100
commitd9533e4c3f36c283681893c66b11343834ca45fa (patch)
tree6f3fc61d92f7ddafa2b26ebdadaa4a84e5a68ec8 /sw/source/filter/html/htmltab.cxx
parenta2cd438a34e911650acf8bbd85840eb8aa36543a (diff)
ofz: dangling pointers
make attribute table a shared_ptr and get HTMLAttrs that belong to it to add a reference to it while they exist Change-Id: I2d3ba433700d4a98fd466b38a495ed5a7adae020 Reviewed-on: https://gerrit.libreoffice.org/46449 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source/filter/html/htmltab.cxx')
-rw-r--r--sw/source/filter/html/htmltab.cxx44
1 files changed, 23 insertions, 21 deletions
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 6810a222c742..18d3a45f62af 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -122,7 +122,7 @@ class HTMLTableContext
public:
- HTMLAttrTable aAttrTab; // attributes
+ std::shared_ptr<HTMLAttrTable> xAttrTab; // attributes
HTMLTableContext( SwPosition *pPs, size_t nCntxtStMin,
size_t nCntxtStAttrMin ) :
@@ -133,9 +133,10 @@ public:
nContextStMin( nCntxtStMin ),
bRestartPRE( false ),
bRestartXMP( false ),
- bRestartListing( false )
+ bRestartListing( false ),
+ xAttrTab(new HTMLAttrTable)
{
- memset( &aAttrTab, 0, sizeof( HTMLAttrTable ));
+ memset(xAttrTab.get(), 0, sizeof(HTMLAttrTable));
}
void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
@@ -3109,7 +3110,7 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl
}
std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken, nColl, aEmptyOUStr, true));
if( SvxAdjust::End != m_eAdjust )
- rParser.InsertAttr(&rParser.m_aAttrTab.pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST),
+ rParser.InsertAttr(&rParser.m_xAttrTab->pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST),
xCntxt.get());
if( SwHTMLParser::HasStyleOptions( m_aStyle, m_aId, m_aClass, &m_aLang, &m_aDir ) )
@@ -3165,7 +3166,7 @@ void CellSaveStruct::InsertCell( SwHTMLParser& rParser,
if( rParser.m_nContextStAttrMin == GetContextStAttrMin() )
{
- HTMLAttr** pTable = reinterpret_cast<HTMLAttr**>(&rParser.m_aAttrTab);
+ HTMLAttr** pTable = reinterpret_cast<HTMLAttr**>(rParser.m_xAttrTab.get());
for( auto nCnt = sizeof( HTMLAttrTable ) / sizeof( HTMLAttr* );
nCnt--; ++pTable )
@@ -3263,7 +3264,7 @@ HTMLTableCnts *SwHTMLParser::InsertTableContents(
const SwNodeIndex& rSttPara = m_pPam->GetPoint()->nNode;
sal_Int32 nSttCnt = m_pPam->GetPoint()->nContent.GetIndex();
- HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab);
+ HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get());
for (sal_uInt16 nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes)
{
HTMLAttr *pAttr = *pHTMLAttributes;
@@ -3422,21 +3423,21 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
HTMLAttr* pTmp =
- new HTMLAttr( *m_pPam->GetPoint(), aFontHeight );
+ new HTMLAttr( *m_pPam->GetPoint(), aFontHeight, nullptr, std::shared_ptr<HTMLAttrTable>() );
m_aSetAttrTab.push_back( pTmp );
SvxFontHeightItem aFontHeightCJK( 40, 100, RES_CHRATR_CJK_FONTSIZE );
pTmp =
- new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCJK );
+ new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCJK, nullptr, std::shared_ptr<HTMLAttrTable>() );
m_aSetAttrTab.push_back( pTmp );
SvxFontHeightItem aFontHeightCTL( 40, 100, RES_CHRATR_CTL_FONTSIZE );
pTmp =
- new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCTL );
+ new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCTL, nullptr, std::shared_ptr<HTMLAttrTable>() );
m_aSetAttrTab.push_back( pTmp );
pTmp = new HTMLAttr( *m_pPam->GetPoint(),
- SvxULSpaceItem( 0, 0, RES_UL_SPACE ) );
+ SvxULSpaceItem( 0, 0, RES_UL_SPACE ), nullptr, std::shared_ptr<HTMLAttrTable>() );
m_aSetAttrTab.push_front( pTmp ); // Position 0, since
// something can be set by
// the table end before
@@ -3482,7 +3483,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
HTMLAttrs *pPostIts = nullptr;
if( !bForceFrame && (bTopTable || pCurTable->HasParentSection()) )
{
- SplitAttrTab( pTCntxt->aAttrTab, bTopTable );
+ SplitAttrTab(pTCntxt->xAttrTab, bTopTable);
// If we reuse a already existing paragraph, we can't add
// PostIts since the paragraph gets behind that table.
// They're gonna be moved into the first paragraph of the table
@@ -3496,7 +3497,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
}
else
{
- SaveAttrTab( pTCntxt->aAttrTab );
+ SaveAttrTab(pTCntxt->xAttrTab);
if( bTopTable && !bAppended )
{
pPostIts = new HTMLAttrs;
@@ -3763,8 +3764,8 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
}
// There could be a section in the cell
- eTabAdjust = m_aAttrTab.pAdjust
- ? static_cast<const SvxAdjustItem&>(m_aAttrTab.pAdjust->GetItem()).
+ eTabAdjust = m_xAttrTab->pAdjust
+ ? static_cast<const SvxAdjustItem&>(m_xAttrTab->pAdjust->GetItem()).
GetAdjust()
: SvxAdjust::End;
}
@@ -4565,12 +4566,13 @@ class CaptionSaveStruct : public SectionSaveStruct
public:
- HTMLAttrTable aAttrTab; // attributes
+ std::shared_ptr<HTMLAttrTable> xAttrTab; // attributes
CaptionSaveStruct( SwHTMLParser& rParser, const SwPosition& rPos ) :
- SectionSaveStruct( rParser ), aSavePos( rPos )
+ SectionSaveStruct( rParser ), aSavePos( rPos ),
+ xAttrTab(new HTMLAttrTable)
{
- rParser.SaveAttrTab( aAttrTab );
+ rParser.SaveAttrTab(xAttrTab);
// The current numbering was remembered and just needs to be closed
aNumRuleInfo.Set( rParser.GetNumInfo() );
@@ -4585,7 +4587,7 @@ public:
Restore( rParser );
// Recover the old attribute tables
- rParser.RestoreAttrTab( aAttrTab );
+ rParser.RestoreAttrTab(xAttrTab);
// Re-open the old numbering
rParser.GetNumInfo().Set( aNumRuleInfo );
@@ -4651,10 +4653,10 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable )
std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::CAPTION_ON));
// Table headers are always centered
- NewAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(SvxAdjust::Center, RES_PARATR_ADJUST) );
+ NewAttr(m_xAttrTab, &m_xAttrTab->pAdjust, SvxAdjustItem(SvxAdjust::Center, RES_PARATR_ADJUST));
HTMLAttrs &rAttrs = xCntxt->GetAttrs();
- rAttrs.push_back( m_aAttrTab.pAdjust );
+ rAttrs.push_back( m_xAttrTab->pAdjust );
PushContext(xCntxt);
@@ -5181,7 +5183,7 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust,
GetNumInfo().Set( pTCntxt->GetNumInfo() );
pTCntxt->RestorePREListingXMP( *this );
- RestoreAttrTab( pTCntxt->aAttrTab );
+ RestoreAttrTab(pTCntxt->xAttrTab);
if (m_xTable == xCurTable && eState != SvParserState::Error)
{