summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-06-26 12:17:27 +0200
committerStephan Bergmann <sbergman@redhat.com>2018-06-26 14:19:36 +0200
commitf5e2dbb40cab1a21dc972806ee4038f52843e838 (patch)
tree9a31eebd39107bd4d84c262e786548ec831af392 /sax
parentd8733e2c59f120acf9feddff04964becc3358621 (diff)
Avoid potential double-delete in ~XMLFile2UTFConverter
...as the implicitly defined copy operations would just copy the m_p* member pointers. Needed some modification of the ParserCleanup class so that Entity (which has a XMLFile2UTFConverter member) can be std::move'd into SaxExpatParser_Impl::pushEntity. Found by new -Wdeprecated-copy of GCC trunk towards GCC 9. Change-Id: I0cb5b5dbcd55249b475ed74b4ac6bcb12f20f2c6 Reviewed-on: https://gerrit.libreoffice.org/56453 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sax')
-rw-r--r--sax/inc/xml2utf.hxx14
-rw-r--r--sax/source/expatwrap/sax_expat.cxx23
-rw-r--r--sax/source/expatwrap/xml2utf.cxx13
3 files changed, 23 insertions, 27 deletions
diff --git a/sax/inc/xml2utf.hxx b/sax/inc/xml2utf.hxx
index 0a26c1f81482..3e6d09cda3a0 100644
--- a/sax/inc/xml2utf.hxx
+++ b/sax/inc/xml2utf.hxx
@@ -20,6 +20,10 @@
#ifndef INCLUDED_SAX_INC_XML2UTF_HXX
#define INCLUDED_SAX_INC_XML2UTF_HXX
+#include <sal/config.h>
+
+#include <memory>
+
#include <sal/types.h>
namespace sax_expatwrap {
@@ -73,13 +77,9 @@ class XMLFile2UTFConverter
{
public:
XMLFile2UTFConverter( ):
- m_bStarted( false ),
- m_pText2Unicode( nullptr ),
- m_pUnicode2Text( nullptr )
+ m_bStarted( false )
{}
- ~XMLFile2UTFConverter();
-
void setInputStream( css::uno::Reference< css::io::XInputStream > const &r ) { m_in = r; }
void setEncoding( const OString &s ) { m_sEncoding = s; }
@@ -116,8 +116,8 @@ private:
bool m_bStarted;
OString m_sEncoding;
- Text2UnicodeConverter *m_pText2Unicode;
- Unicode2TextConverter *m_pUnicode2Text;
+ std::unique_ptr<Text2UnicodeConverter> m_pText2Unicode;
+ std::unique_ptr<Unicode2TextConverter> m_pUnicode2Text;
};
}
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx
index 49f9471b7b03..b7e76d4eb207 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -20,6 +20,7 @@
#include <string.h>
#include <cassert>
#include <memory>
+#include <utility>
#include <vector>
@@ -159,8 +160,8 @@ public: // module scope
// External entity stack
vector<struct Entity> vecEntity;
- void pushEntity( const struct Entity &entity )
- { vecEntity.push_back( entity ); }
+ void pushEntity( Entity &&entity )
+ { vecEntity.push_back( std::move(entity) ); }
void popEntity()
{ vecEntity.pop_back( ); }
struct Entity &getEntity()
@@ -388,18 +389,18 @@ class ParserCleanup
{
private:
SaxExpatParser_Impl& m_rParser;
- Entity& m_rEntity;
+ XML_Parser m_xmlParser;
public:
- ParserCleanup(SaxExpatParser_Impl& rParser, Entity& rEntity)
+ ParserCleanup(SaxExpatParser_Impl& rParser, XML_Parser xmlParser)
: m_rParser(rParser)
- , m_rEntity(rEntity)
+ , m_xmlParser(xmlParser)
{
}
~ParserCleanup()
{
m_rParser.popEntity();
//XML_ParserFree accepts a null arg
- XML_ParserFree(m_rEntity.pParser);
+ XML_ParserFree(m_xmlParser);
}
};
@@ -469,9 +470,10 @@ void SaxExpatParser::parseStream( const InputSource& structSource)
m_pImpl->exception = SAXParseException();
- m_pImpl->pushEntity( entity );
+ auto const xmlParser = entity.pParser;
+ m_pImpl->pushEntity( std::move(entity) );
- ParserCleanup aEnsureFree(*m_pImpl, entity);
+ ParserCleanup aEnsureFree(*m_pImpl, xmlParser);
// start the document
if( m_pImpl->rDocumentHandler.is() ) {
@@ -847,7 +849,8 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef(
}
entity.converter.setInputStream( entity.structSource.aInputStream );
- pImpl->pushEntity( entity );
+ auto const xmlParser = entity.pParser;
+ pImpl->pushEntity( std::move(entity) );
try
{
pImpl->parse();
@@ -870,7 +873,7 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef(
pImpl->popEntity();
- XML_ParserFree( entity.pParser );
+ XML_ParserFree( xmlParser );
}
return bOK;
diff --git a/sax/source/expatwrap/xml2utf.cxx b/sax/source/expatwrap/xml2utf.cxx
index 549910af2a88..6b240ae8b3f0 100644
--- a/sax/source/expatwrap/xml2utf.cxx
+++ b/sax/source/expatwrap/xml2utf.cxx
@@ -22,6 +22,7 @@
#include <sal/types.h>
+#include <o3tl/make_unique.hxx>
#include <rtl/textenc.h>
#include <rtl/tencinfo.h>
#include <com/sun/star/io/NotConnectedException.hpp>
@@ -114,14 +115,6 @@ sal_Int32 XMLFile2UTFConverter::readAndConvert( Sequence<sal_Int8> &seq , sal_In
return nRead;
}
-
-XMLFile2UTFConverter::~XMLFile2UTFConverter()
-{
- delete m_pText2Unicode;
- delete m_pUnicode2Text;
-}
-
-
void XMLFile2UTFConverter::removeEncoding( Sequence<sal_Int8> &seq )
{
const sal_Int8 *pSource = seq.getArray();
@@ -331,8 +324,8 @@ void XMLFile2UTFConverter::initializeDecoding()
rtl_TextEncoding encoding = rtl_getTextEncodingFromMimeCharset( m_sEncoding.getStr() );
if( encoding != RTL_TEXTENCODING_UTF8 )
{
- m_pText2Unicode = new Text2UnicodeConverter( m_sEncoding );
- m_pUnicode2Text = new Unicode2TextConverter( RTL_TEXTENCODING_UTF8 );
+ m_pText2Unicode = o3tl::make_unique<Text2UnicodeConverter>( m_sEncoding );
+ m_pUnicode2Text = o3tl::make_unique<Unicode2TextConverter>( RTL_TEXTENCODING_UTF8 );
}
}
}