summaryrefslogtreecommitdiff
path: root/sd/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-10-26 21:11:29 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-10-26 21:17:20 +0100
commitad5a6b4d589ed7e13a5bb57339826021d377c046 (patch)
tree1aa9c676ee4e9a3b9ac9613333f6b4b821e8b747 /sd/source
parentdad2f1440c1fed230da40927503e30267ce1fa84 (diff)
fix leak in HeaderFooterTabPage seen examining coverity#1371205
In the case that the field data is not a SvxDateTimeField or SvxDateField then the old "aFieldInfo.pFieldItem = nullptr" call will mean that the pFieldItem is leaked for that element. The only thing needed later is the existance of a date field, and the field's position, so encode those two facts as a bool and EPosition and stop abusing aFieldInfo.pFieldItem to serve as a flag Change-Id: I6a1c46d32406dbd6865cfcf6d23a3863bada6810
Diffstat (limited to 'sd/source')
-rw-r--r--sd/source/ui/dlg/headerfooterdlg.cxx35
1 files changed, 20 insertions, 15 deletions
diff --git a/sd/source/ui/dlg/headerfooterdlg.cxx b/sd/source/ui/dlg/headerfooterdlg.cxx
index 0230762706b5..fa7bdf9bb3f9 100644
--- a/sd/source/ui/dlg/headerfooterdlg.cxx
+++ b/sd/source/ui/dlg/headerfooterdlg.cxx
@@ -627,35 +627,38 @@ void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, boo
if( pOPO )
pOutl->SetText( *pOPO );
- EFieldInfo aFieldInfo;
- aFieldInfo.pFieldItem = nullptr;
+ EPosition aDateFieldPosition;
+ bool bHasDateFieldItem = false;
sal_Int32 nParaCount = pEdit->GetParagraphCount();
- sal_Int32 nPara;
- for( nPara = 0; (nPara < nParaCount) && (aFieldInfo.pFieldItem == nullptr); nPara++ )
+ for (sal_Int32 nPara = 0; (nPara < nParaCount) && !bHasDateFieldItem; ++nPara)
{
- sal_uInt16 nFieldCount = pEdit->GetFieldCount( nPara );
- sal_uInt16 nField;
- for( nField = 0; (nField < nFieldCount) && (aFieldInfo.pFieldItem == nullptr); nField++ )
+ sal_uInt16 nFieldCount = pEdit->GetFieldCount(nPara);
+ for (sal_uInt16 nField = 0; (nField < nFieldCount) && !bHasDateFieldItem; ++nField)
{
- aFieldInfo = pEdit->GetFieldInfo( nPara, nField );
- if( aFieldInfo.pFieldItem )
+ EFieldInfo aFieldInfo = pEdit->GetFieldInfo(nPara, nField);
+ if (aFieldInfo.pFieldItem)
{
const SvxFieldData* pFieldData = aFieldInfo.pFieldItem->GetField();
- if( pFieldData && ( dynamic_cast< const SvxDateTimeField *>( pFieldData ) != nullptr || dynamic_cast< const SvxDateField *>( pFieldData ) != nullptr))
+ if (dynamic_cast<const SvxDateTimeField*>(pFieldData) != nullptr ||
+ dynamic_cast<const SvxDateField*>(pFieldData) != nullptr)
{
+ bHasDateFieldItem = true;
+ aDateFieldPosition = aFieldInfo.aPosition;
break;
}
}
- aFieldInfo.pFieldItem = nullptr;
}
}
- if( aFieldInfo.pFieldItem != nullptr )
+ if (bHasDateFieldItem)
{
if( bSet )
{
- SfxItemSet aSet( pEdit->GetAttribs( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex, aFieldInfo.aPosition.nIndex+1, GetAttribsFlags::CHARATTRIBS ) );
+ SfxItemSet aSet(pEdit->GetAttribs(aDateFieldPosition.nPara,
+ aDateFieldPosition.nIndex,
+ aDateFieldPosition.nIndex+1,
+ GetAttribsFlags::CHARATTRIBS));
SvxLanguageItem aItem( rLanguage, EE_CHAR_LANGUAGE );
aSet.Put( aItem );
@@ -666,7 +669,8 @@ void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, boo
SvxLanguageItem aItemCTL( rLanguage, EE_CHAR_LANGUAGE_CTL );
aSet.Put( aItemCTL );
- ESelection aSel( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex, aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex+1 );
+ ESelection aSel(aDateFieldPosition.nPara, aDateFieldPosition.nIndex,
+ aDateFieldPosition.nPara, aDateFieldPosition.nIndex+1 );
pEdit->QuickSetAttribs( aSet, aSel );
pObj->SetOutlinerParaObject( pOutl->CreateParaObject() );
@@ -674,7 +678,8 @@ void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, boo
}
else
{
- rLanguage = pOutl->GetLanguage( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex );
+ rLanguage = pOutl->GetLanguage(aDateFieldPosition.nPara,
+ aDateFieldPosition.nIndex );
}
}