Kaydet (Commit) dbf87d21 authored tarafından Michael Stahl's avatar Michael Stahl

coverity#1372990 xmloff: use unique_ptr for RewindMaps

Change-Id: I51e67607d94a465ce39e822f01a0c60efbf1a0f0
üst c480677f
...@@ -43,10 +43,10 @@ class XMLOFF_DLLPUBLIC SvXMLImportContext : public ::cppu::WeakImplHelper1< ::cs ...@@ -43,10 +43,10 @@ class XMLOFF_DLLPUBLIC SvXMLImportContext : public ::cppu::WeakImplHelper1< ::cs
sal_uInt16 mnPrefix; sal_uInt16 mnPrefix;
OUString maLocalName; OUString maLocalName;
std::unique_ptr<SvXMLNamespaceMap> mxRewindMap; std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap;
SAL_DLLPRIVATE SvXMLNamespaceMap *TakeRewindMap() { return mxRewindMap.release(); } SAL_DLLPRIVATE std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_pRewindMap); }
SAL_DLLPRIVATE void PutRewindMap( SvXMLNamespaceMap *p ) { mxRewindMap.reset(p); } SAL_DLLPRIVATE void PutRewindMap(std::unique_ptr<SvXMLNamespaceMap> p) { m_pRewindMap = std::move(p); }
protected: protected:
......
...@@ -175,7 +175,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8< ...@@ -175,7 +175,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
std::unique_ptr<SvXMLImport_Impl> mpImpl; // dummy std::unique_ptr<SvXMLImport_Impl> mpImpl; // dummy
SvXMLNamespaceMap *mpNamespaceMap; std::unique_ptr<SvXMLNamespaceMap> mpNamespaceMap;
std::unique_ptr<SvXMLUnitConverter> mpUnitConv; std::unique_ptr<SvXMLUnitConverter> mpUnitConv;
SvXMLImportContexts_Impl maContexts; SvXMLImportContexts_Impl maContexts;
FastSvXMLImportContexts_Impl maFastContexts; FastSvXMLImportContexts_Impl maFastContexts;
...@@ -200,7 +200,8 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8< ...@@ -200,7 +200,8 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
const OUString getNamespacePrefixFromToken( sal_Int32 nToken ); const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
void registerNamespaces(); void registerNamespaces();
void registerNSHelper(sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace ); 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); void Characters(const OUString& aChars);
protected: protected:
......
...@@ -447,8 +447,6 @@ SvXMLImport::SvXMLImport( ...@@ -447,8 +447,6 @@ SvXMLImport::SvXMLImport(
SvXMLImport::~SvXMLImport() throw () SvXMLImport::~SvXMLImport() throw ()
{ {
delete mpNamespaceMap;
if (mxEventListener.is() && mxModel.is()) if (mxEventListener.is() && mxModel.is())
mxModel->removeEventListener(mxEventListener); mxModel->removeEventListener(mxEventListener);
} }
...@@ -659,9 +657,10 @@ void SAL_CALL SvXMLImport::endDocument() ...@@ -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; sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; i++ ) for( sal_Int16 i=0; i < nAttrCount; i++ )
{ {
...@@ -685,8 +684,8 @@ SvXMLNamespaceMap* SvXMLImport::processNSAttributes(const uno::Reference< xml::s ...@@ -685,8 +684,8 @@ SvXMLNamespaceMap* SvXMLImport::processNSAttributes(const uno::Reference< xml::s
{ {
if( !pRewindMap ) if( !pRewindMap )
{ {
pRewindMap = mpNamespaceMap; pRewindMap = std::move(mpNamespaceMap);
mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap ); mpNamespaceMap.reset(new SvXMLNamespaceMap(*pRewindMap));
} }
const OUString& rAttrValue = xAttrList->getValueByIndex( i ); const OUString& rAttrValue = xAttrList->getValueByIndex( i );
...@@ -719,7 +718,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName, ...@@ -719,7 +718,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
// SAL_INFO("svg", "startElement " << rName); // SAL_INFO("svg", "startElement " << rName);
// Process namespace attributes. This must happen before creating the // Process namespace attributes. This must happen before creating the
// context, because namespace decaration apply to the element name itself. // 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. // Get element's namespace and local name.
OUString aLocalName; OUString aLocalName;
...@@ -759,7 +758,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName, ...@@ -759,7 +758,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
// Remember old namespace map. // Remember old namespace map.
if( pRewindMap ) if( pRewindMap )
xContext->PutRewindMap( pRewindMap ); xContext->PutRewindMap(std::move(pRewindMap));
// Call a startElement at the new context. // Call a startElement at the new context.
xContext->StartElement( xAttrList ); xContext->StartElement( xAttrList );
...@@ -782,7 +781,7 @@ rName ...@@ -782,7 +781,7 @@ rName
return; return;
} }
SvXMLNamespaceMap * pRewindMap(nullptr); std::unique_ptr<SvXMLNamespaceMap> pRewindMap;
{ {
// Get topmost context and remove it from the stack. // Get topmost context and remove it from the stack.
...@@ -808,8 +807,8 @@ rName ...@@ -808,8 +807,8 @@ rName
// Rewind a namespace map. // Rewind a namespace map.
if (pRewindMap) if (pRewindMap)
{ {
delete mpNamespaceMap; mpNamespaceMap.reset();
mpNamespaceMap = pRewindMap; mpNamespaceMap = std::move(pRewindMap);
} }
} }
...@@ -879,10 +878,11 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element, ...@@ -879,10 +878,11 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
{ {
rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList; rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
maNamespaceHandler->addNSDeclAttributes( rAttrList ); maNamespaceHandler->addNSDeclAttributes( rAttrList );
SvXMLNamespaceMap *pRewindMap = processNSAttributes(rAttrList.get()); std::unique_ptr<SvXMLNamespaceMap> pRewindMap(
processNSAttributes(rAttrList.get()));
SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() ); SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() );
if( pContext && pRewindMap ) if( pContext && pRewindMap )
pContext->PutRewindMap( pRewindMap ); pContext->PutRewindMap(std::move(pRewindMap));
maContexts.push_back( pContext ); maContexts.push_back( pContext );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment