From 05f97ef127ec6ee0cc159fc74b4fecc34d9c684c Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 7 Dec 2017 16:37:13 +0000 Subject: coverity#1425723 silence 'Wrapper object use after free' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibcc0e5f28910bdd15c94579d754de3698ac8beb1 Reviewed-on: https://gerrit.libreoffice.org/46035 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sc/source/filter/xml/xmlcondformat.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'sc') diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx index 1d2cab79dd76..4925563b1502 100644 --- a/sc/source/filter/xml/xmlcondformat.cxx +++ b/sc/source/filter/xml/xmlcondformat.cxx @@ -325,7 +325,16 @@ void SAL_CALL ScXMLConditionalFormatContext::endFastElement( sal_Int32 /*nElemen } } } + } + + sal_uLong nIndex = pDoc->AddCondFormat(pFormat.release(), nTab); + ScConditionalFormat* pInsertedFormat = pDoc->GetCondFormList(nTab)->GetFormat(nIndex); + assert(pInsertedFormat && pInsertedFormat->GetKey() == nIndex); + mrParent.mvCondFormatData.push_back( { pInsertedFormat, nTab } ); + + if (bEligibleForCache) + { // Not found in cache, replace oldest cache entry sal_Int64 nOldestAge = -1; size_t nIndexOfOldest = 0; @@ -337,17 +346,11 @@ void SAL_CALL ScXMLConditionalFormatContext::endFastElement( sal_Int32 /*nElemen nIndexOfOldest = (&aCacheEntry - &mrParent.maCache.front()); } } - mrParent.maCache[nIndexOfOldest].mpFormat = pFormat.get(); + mrParent.maCache[nIndexOfOldest].mpFormat = pInsertedFormat; mrParent.maCache[nIndexOfOldest].mbSingleRelativeReference = bSingleRelativeReference; mrParent.maCache[nIndexOfOldest].mpTokens.reset(pTokens); mrParent.maCache[nIndexOfOldest].mnAge = 0; } - - sal_uLong nIndex = pDoc->AddCondFormat(pFormat.get(), nTab); - (void) nIndex; // Avoid 'unused variable' warning when assert() expands to empty - assert(pFormat->GetKey() == nIndex); - - mrParent.mvCondFormatData.push_back( { pFormat.release(), nTab } ); } ScXMLConditionalFormatContext::~ScXMLConditionalFormatContext() -- cgit