Kaydet (Commit) 7e937a13 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in Inflater,Deflater

Change-Id: I55833664a6e76d781908b8f1f721dd9a4946e35f
Reviewed-on: https://gerrit.libreoffice.org/53224Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 18c27429
...@@ -42,6 +42,9 @@ public: ...@@ -42,6 +42,9 @@ public:
// this just too clever for me // this just too clever for me
if (fn == SRCDIR "/sc/source/core/tool/chgtrack.cxx") if (fn == SRCDIR "/sc/source/core/tool/chgtrack.cxx")
return; return;
// too clever
if (fn == SRCDIR "/pyuno/source/module/pyuno_runtime.cxx")
return;
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <package/packagedllapi.hxx> #include <package/packagedllapi.hxx>
#include <memory>
struct z_stream_s; struct z_stream_s;
...@@ -35,7 +36,7 @@ class DLLPUBLIC_PACKAGE Deflater final ...@@ -35,7 +36,7 @@ class DLLPUBLIC_PACKAGE Deflater final
bool bFinish; bool bFinish;
bool bFinished; bool bFinished;
sal_Int64 nOffset, nLength; sal_Int64 nOffset, nLength;
z_stream* pStream; std::unique_ptr<z_stream> pStream;
void init (sal_Int32 nLevel, bool bNowrap); void init (sal_Int32 nLevel, bool bNowrap);
sal_Int32 doDeflateBytes (css::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength); sal_Int32 doDeflateBytes (css::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <package/packagedllapi.hxx> #include <package/packagedllapi.hxx>
#include <memory>
struct z_stream_s; struct z_stream_s;
...@@ -33,7 +34,7 @@ class DLLPUBLIC_PACKAGE Inflater final ...@@ -33,7 +34,7 @@ class DLLPUBLIC_PACKAGE Inflater final
bool bFinished, bNeedDict; bool bFinished, bNeedDict;
sal_Int32 nOffset, nLength, nLastInflateError; sal_Int32 nOffset, nLength, nLastInflateError;
z_stream* pStream; std::unique_ptr<z_stream> pStream;
css::uno::Sequence < sal_Int8 > sInBuffer; css::uno::Sequence < sal_Int8 > sInBuffer;
sal_Int32 doInflateBytes (css::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength); sal_Int32 doInflateBytes (css::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength);
......
...@@ -37,20 +37,20 @@ Deflater::~Deflater() ...@@ -37,20 +37,20 @@ Deflater::~Deflater()
} }
void Deflater::init (sal_Int32 nLevelArg, bool bNowrap) 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 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)) DEF_MEM_LEVEL, DEFAULT_STRATEGY))
{ {
case Z_OK: case Z_OK:
break; break;
case Z_MEM_ERROR: case Z_MEM_ERROR:
delete pStream; pStream.reset();
break; break;
case Z_STREAM_ERROR: case Z_STREAM_ERROR:
delete pStream; pStream.reset();
break; break;
default: default:
break; break;
...@@ -75,9 +75,9 @@ sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int ...@@ -75,9 +75,9 @@ sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int
pStream->avail_out = nNewLength; pStream->avail_out = nNewLength;
#if !defined Z_PREFIX #if !defined Z_PREFIX
nResult = deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); nResult = deflate(pStream.get(), bFinish ? Z_FINISH : Z_NO_FLUSH);
#else #else
nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH); nResult = z_deflate(pStream.get(), bFinish ? Z_FINISH : Z_NO_FLUSH);
#endif #endif
switch (nResult) switch (nResult)
{ {
...@@ -124,9 +124,9 @@ sal_Int64 Deflater::getTotalOut( ) ...@@ -124,9 +124,9 @@ sal_Int64 Deflater::getTotalOut( )
void Deflater::reset( ) void Deflater::reset( )
{ {
#if !defined Z_PREFIX #if !defined Z_PREFIX
deflateReset(pStream); deflateReset(pStream.get());
#else #else
z_deflateReset(pStream); z_deflateReset(pStream.get());
#endif #endif
bFinish = false; bFinish = false;
bFinished = false; bFinished = false;
...@@ -134,16 +134,15 @@ void Deflater::reset( ) ...@@ -134,16 +134,15 @@ void Deflater::reset( )
} }
void Deflater::end( ) void Deflater::end( )
{ {
if (pStream != nullptr) if (pStream)
{ {
#if !defined Z_PREFIX #if !defined Z_PREFIX
deflateEnd(pStream); deflateEnd(pStream.get());
#else #else
z_deflateEnd(pStream); z_deflateEnd(pStream.get());
#endif #endif
delete pStream; pStream.reset();
} }
pStream = nullptr;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -34,20 +34,20 @@ Inflater::Inflater(bool bNoWrap) ...@@ -34,20 +34,20 @@ Inflater::Inflater(bool bNoWrap)
nLastInflateError(0), nLastInflateError(0),
pStream(nullptr) pStream(nullptr)
{ {
pStream = new z_stream; pStream.reset(new z_stream);
/* memset to 0 to set zalloc/opaque etc */ /* memset to 0 to set zalloc/opaque etc */
memset (pStream, 0, sizeof(*pStream)); memset (pStream.get(), 0, sizeof(*pStream));
sal_Int32 nRes; sal_Int32 nRes;
nRes = inflateInit2(pStream, bNoWrap ? -MAX_WBITS : MAX_WBITS); nRes = inflateInit2(pStream.get(), bNoWrap ? -MAX_WBITS : MAX_WBITS);
switch (nRes) switch (nRes)
{ {
case Z_OK: case Z_OK:
break; break;
case Z_MEM_ERROR: case Z_MEM_ERROR:
delete pStream; pStream.reset();
break; break;
case Z_STREAM_ERROR: case Z_STREAM_ERROR:
delete pStream; pStream.reset();
break; break;
default: default:
break; break;
...@@ -78,16 +78,15 @@ sal_Int32 Inflater::doInflateSegment( Sequence< sal_Int8 >& rBuffer, sal_Int32 n ...@@ -78,16 +78,15 @@ sal_Int32 Inflater::doInflateSegment( Sequence< sal_Int8 >& rBuffer, sal_Int32 n
void Inflater::end( ) void Inflater::end( )
{ {
if (pStream != nullptr) if (pStream)
{ {
#if !defined Z_PREFIX #if !defined Z_PREFIX
inflateEnd(pStream); inflateEnd(pStream.get());
#else #else
z_inflateEnd(pStream); z_inflateEnd(pStream.get());
#endif #endif
delete pStream; pStream.reset();
} }
pStream = nullptr;
} }
sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength) 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 ...@@ -106,9 +105,9 @@ sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 n
pStream->avail_out = nNewLength; pStream->avail_out = nNewLength;
#if !defined Z_PREFIX #if !defined Z_PREFIX
sal_Int32 nResult = ::inflate(pStream, Z_PARTIAL_FLUSH); sal_Int32 nResult = ::inflate(pStream.get(), Z_PARTIAL_FLUSH);
#else #else
sal_Int32 nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH); sal_Int32 nResult = ::z_inflate(pStream.get(), Z_PARTIAL_FLUSH);
#endif #endif
switch (nResult) switch (nResult)
......
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