[Libreoffice-commits] core.git: include/xmloff xmloff/source

Michael Stahl mstahl at redhat.com
Fri Sep 16 12:37:41 UTC 2016


 include/xmloff/xmlictxt.hxx   |    6 +++---
 include/xmloff/xmlimp.hxx     |    5 +++--
 xmloff/source/core/xmlimp.cxx |   26 +++++++++++++-------------
 3 files changed, 19 insertions(+), 18 deletions(-)

New commits:
commit dbf87d2124a0c01014b9e839804455d3be38831f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Sep 16 14:26:50 2016 +0200

    coverity#1372990 xmloff: use unique_ptr for RewindMaps
    
    Change-Id: I51e67607d94a465ce39e822f01a0c60efbf1a0f0

diff --git a/include/xmloff/xmlictxt.hxx b/include/xmloff/xmlictxt.hxx
index 6e064e2..6d24112 100644
--- a/include/xmloff/xmlictxt.hxx
+++ b/include/xmloff/xmlictxt.hxx
@@ -43,10 +43,10 @@ class XMLOFF_DLLPUBLIC SvXMLImportContext : public ::cppu::WeakImplHelper1< ::cs
     sal_uInt16       mnPrefix;
     OUString maLocalName;
 
-    std::unique_ptr<SvXMLNamespaceMap>   mxRewindMap;
+    std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap;
 
-    SAL_DLLPRIVATE SvXMLNamespaceMap *TakeRewindMap() { return mxRewindMap.release(); }
-    SAL_DLLPRIVATE void PutRewindMap( SvXMLNamespaceMap *p ) { mxRewindMap.reset(p); }
+    SAL_DLLPRIVATE std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_pRewindMap); }
+    SAL_DLLPRIVATE void PutRewindMap(std::unique_ptr<SvXMLNamespaceMap> p) { m_pRewindMap = std::move(p); }
 
 protected:
 
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index cc54fe1..87634e7 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -175,7 +175,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
 
     std::unique_ptr<SvXMLImport_Impl>  mpImpl;            // dummy
 
-    SvXMLNamespaceMap           *mpNamespaceMap;
+    std::unique_ptr<SvXMLNamespaceMap> mpNamespaceMap;
     std::unique_ptr<SvXMLUnitConverter> mpUnitConv;
     SvXMLImportContexts_Impl    maContexts;
     FastSvXMLImportContexts_Impl    maFastContexts;
@@ -200,7 +200,8 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
     const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
     void registerNamespaces();
     void registerNSHelper(sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace );
-    SvXMLNamespaceMap* processNSAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList);
+    std::unique_ptr<SvXMLNamespaceMap> processNSAttributes(
+        const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList);
     void Characters(const OUString& aChars);
 
 protected:
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 52df8ce..715ddb9 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -447,8 +447,6 @@ SvXMLImport::SvXMLImport(
 
 SvXMLImport::~SvXMLImport() throw ()
 {
-    delete mpNamespaceMap;
-
     if (mxEventListener.is() && mxModel.is())
         mxModel->removeEventListener(mxEventListener);
 }
@@ -659,9 +657,10 @@ void SAL_CALL SvXMLImport::endDocument()
     }
 }
 
-SvXMLNamespaceMap* SvXMLImport::processNSAttributes(const uno::Reference< xml::sax::XAttributeList >& xAttrList)
+std::unique_ptr<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
+        const uno::Reference< xml::sax::XAttributeList >& xAttrList)
 {
-    SvXMLNamespaceMap *pRewindMap = nullptr;
+    std::unique_ptr<SvXMLNamespaceMap> pRewindMap;
     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     for( sal_Int16 i=0; i < nAttrCount; i++ )
     {
@@ -685,8 +684,8 @@ SvXMLNamespaceMap* SvXMLImport::processNSAttributes(const uno::Reference< xml::s
         {
             if( !pRewindMap )
             {
-                pRewindMap = mpNamespaceMap;
-                mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
+                pRewindMap = std::move(mpNamespaceMap);
+                mpNamespaceMap.reset(new SvXMLNamespaceMap(*pRewindMap));
             }
             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
 
@@ -719,7 +718,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
     //    SAL_INFO("svg", "startElement " << rName);
     // Process namespace attributes. This must happen before creating the
     // context, because namespace decaration apply to the element name itself.
-    SvXMLNamespaceMap *pRewindMap = processNSAttributes(xAttrList);
+    std::unique_ptr<SvXMLNamespaceMap> pRewindMap(processNSAttributes(xAttrList));
 
     // Get element's namespace and local name.
     OUString aLocalName;
@@ -759,7 +758,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
 
     // Remember old namespace map.
     if( pRewindMap )
-        xContext->PutRewindMap( pRewindMap );
+        xContext->PutRewindMap(std::move(pRewindMap));
 
     // Call a startElement at the new context.
     xContext->StartElement( xAttrList );
@@ -782,7 +781,7 @@ rName
         return;
     }
 
-    SvXMLNamespaceMap * pRewindMap(nullptr);
+    std::unique_ptr<SvXMLNamespaceMap> pRewindMap;
 
     {
         // Get topmost context and remove it from the stack.
@@ -808,8 +807,8 @@ rName
     // Rewind a namespace map.
     if (pRewindMap)
     {
-        delete mpNamespaceMap;
-        mpNamespaceMap = pRewindMap;
+        mpNamespaceMap.reset();
+        mpNamespaceMap = std::move(pRewindMap);
     }
 }
 
@@ -879,10 +878,11 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
     {
         rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
         maNamespaceHandler->addNSDeclAttributes( rAttrList );
-        SvXMLNamespaceMap *pRewindMap = processNSAttributes(rAttrList.get());
+        std::unique_ptr<SvXMLNamespaceMap> pRewindMap(
+                processNSAttributes(rAttrList.get()));
         SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() );
         if( pContext && pRewindMap )
-            pContext->PutRewindMap( pRewindMap );
+            pContext->PutRewindMap(std::move(pRewindMap));
         maContexts.push_back( pContext );
     }
 


More information about the Libreoffice-commits mailing list