sc/source/filter/xml/xmlcondformat.cxx |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

New commits:
commit 05f97ef127ec6ee0cc159fc74b4fecc34d9c684c
Author: Caolán McNamara <caol...@redhat.com>
Date:   Thu Dec 7 16:37:13 2017 +0000

    coverity#1425723 silence 'Wrapper object use after free'
    
    Change-Id: Ibcc0e5f28910bdd15c94579d754de3698ac8beb1
    Reviewed-on: https://gerrit.libreoffice.org/46035
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

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()
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to