diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-16 12:06:48 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-23 08:14:07 +0200 |
commit | 7e937a13840129b1aba0ffcc560dc07e891ebe09 (patch) | |
tree | d34dccc224deaab034588a244d94ac7aa27d9f0c /package | |
parent | 18c2742946a745d5311a1c26bda352cefc6c1ac0 (diff) |
loplugin:useuniqueptr in Inflater,Deflater
Change-Id: I55833664a6e76d781908b8f1f721dd9a4946e35f
Reviewed-on: https://gerrit.libreoffice.org/53224
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package')
-rw-r--r-- | package/source/zipapi/Deflater.cxx | 27 | ||||
-rw-r--r-- | package/source/zipapi/Inflater.cxx | 23 |
2 files changed, 24 insertions, 26 deletions
diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx index e2f0e7ebd374..d50317357ef1 100644 --- a/package/source/zipapi/Deflater.cxx +++ b/package/source/zipapi/Deflater.cxx @@ -37,20 +37,20 @@ Deflater::~Deflater() } void Deflater::init (sal_Int32 nLevelArg, bool bNowrap) { - pStream = new z_stream; + pStream.reset(new z_stream); /* Memset it to 0...sets zalloc/zfree/opaque to NULL */ - memset (pStream, 0, sizeof(*pStream)); + memset (pStream.get(), 0, sizeof(*pStream)); - switch (deflateInit2(pStream, nLevelArg, Z_DEFLATED, bNowrap? -MAX_WBITS : MAX_WBITS, + switch (deflateInit2(pStream.get(), nLevelArg, Z_DEFLATED, bNowrap? -MAX_WBITS : MAX_WBITS, DEF_MEM_LEVEL, DEFAULT_STRATEGY)) { case Z_OK: break; case Z_MEM_ERROR: - delete pStream; + pStream.reset(); break; case Z_STREAM_ERROR: - delete pStream; + pStream.reset(); break; default: break; @@ -75,9 +75,9 @@ sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int pStream->avail_out = nNewLength; #if !defined Z_PREFIX - nResult = deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); + nResult = deflate(pStream.get(), bFinish ? Z_FINISH : Z_NO_FLUSH); #else - nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); + nResult = z_deflate(pStream.get(), bFinish ? Z_FINISH : Z_NO_FLUSH); #endif switch (nResult) { @@ -124,9 +124,9 @@ sal_Int64 Deflater::getTotalOut( ) void Deflater::reset( ) { #if !defined Z_PREFIX - deflateReset(pStream); + deflateReset(pStream.get()); #else - z_deflateReset(pStream); + z_deflateReset(pStream.get()); #endif bFinish = false; bFinished = false; @@ -134,16 +134,15 @@ void Deflater::reset( ) } void Deflater::end( ) { - if (pStream != nullptr) + if (pStream) { #if !defined Z_PREFIX - deflateEnd(pStream); + deflateEnd(pStream.get()); #else - z_deflateEnd(pStream); + z_deflateEnd(pStream.get()); #endif - delete pStream; + pStream.reset(); } - pStream = nullptr; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx index a059eb1418de..24a3b23e3156 100644 --- a/package/source/zipapi/Inflater.cxx +++ b/package/source/zipapi/Inflater.cxx @@ -34,20 +34,20 @@ Inflater::Inflater(bool bNoWrap) nLastInflateError(0), pStream(nullptr) { - pStream = new z_stream; + pStream.reset(new z_stream); /* memset to 0 to set zalloc/opaque etc */ - memset (pStream, 0, sizeof(*pStream)); + memset (pStream.get(), 0, sizeof(*pStream)); sal_Int32 nRes; - nRes = inflateInit2(pStream, bNoWrap ? -MAX_WBITS : MAX_WBITS); + nRes = inflateInit2(pStream.get(), bNoWrap ? -MAX_WBITS : MAX_WBITS); switch (nRes) { case Z_OK: break; case Z_MEM_ERROR: - delete pStream; + pStream.reset(); break; case Z_STREAM_ERROR: - delete pStream; + pStream.reset(); break; default: break; @@ -78,16 +78,15 @@ sal_Int32 Inflater::doInflateSegment( Sequence< sal_Int8 >& rBuffer, sal_Int32 n void Inflater::end( ) { - if (pStream != nullptr) + if (pStream) { #if !defined Z_PREFIX - inflateEnd(pStream); + inflateEnd(pStream.get()); #else - z_inflateEnd(pStream); + z_inflateEnd(pStream.get()); #endif - delete pStream; + pStream.reset(); } - pStream = nullptr; } sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength) @@ -106,9 +105,9 @@ sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 n pStream->avail_out = nNewLength; #if !defined Z_PREFIX - sal_Int32 nResult = ::inflate(pStream, Z_PARTIAL_FLUSH); + sal_Int32 nResult = ::inflate(pStream.get(), Z_PARTIAL_FLUSH); #else - sal_Int32 nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH); + sal_Int32 nResult = ::z_inflate(pStream.get(), Z_PARTIAL_FLUSH); #endif switch (nResult) |