[Libreoffice-commits] core.git: sd/source
Caolán McNamara
caolanm at redhat.com
Wed Oct 26 20:17:49 UTC 2016
sd/source/ui/dlg/headerfooterdlg.cxx | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
New commits:
commit ad5a6b4d589ed7e13a5bb57339826021d377c046
Author: Caolán McNamara <caolanm at redhat.com>
Date: Wed Oct 26 21:11:29 2016 +0100
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
diff --git a/sd/source/ui/dlg/headerfooterdlg.cxx b/sd/source/ui/dlg/headerfooterdlg.cxx
index 02307627..fa7bdf9 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 );
}
}
More information about the Libreoffice-commits
mailing list