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

loplugin:useuniqueptr in lotuswordpro

Change-Id: Ib34984180cea7143b6595decba785f1b55d15e2c
Reviewed-on: https://gerrit.libreoffice.org/60336
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 7e69b971
...@@ -147,15 +147,14 @@ std::unique_ptr<XFBGImage> LwpBackgroundStuff::GetFillPattern() ...@@ -147,15 +147,14 @@ std::unique_ptr<XFBGImage> LwpBackgroundStuff::GetFillPattern()
aXOBitmap.Array2Bitmap(); aXOBitmap.Array2Bitmap();
WriteDIB(aXOBitmap.GetBitmap(), aPicMemStream); WriteDIB(aXOBitmap.GetBitmap(), aPicMemStream);
sal_uInt32 nSize = aPicMemStream.GetEndOfData(); sal_uInt32 nSize = aPicMemStream.GetEndOfData();
sal_uInt8* pImageBuff = new sal_uInt8 [nSize]; std::unique_ptr<sal_uInt8[]> pImageBuff(new sal_uInt8 [nSize]);
memcpy(pImageBuff, aPicMemStream.GetData(), nSize); memcpy(pImageBuff.get(), aPicMemStream.GetData(), nSize);
// create XFBGImage object. // create XFBGImage object.
std::unique_ptr<XFBGImage> xXFBGImage(new XFBGImage); std::unique_ptr<XFBGImage> xXFBGImage(new XFBGImage);
xXFBGImage->SetImageData(pImageBuff, nSize); xXFBGImage->SetImageData(pImageBuff.get(), nSize);
delete [] pImageBuff; pImageBuff.reset();
pImageBuff = nullptr;
xXFBGImage->SetRepeate(); xXFBGImage->SetRepeate();
......
...@@ -116,8 +116,8 @@ void LwpDocData::Read() ...@@ -116,8 +116,8 @@ void LwpDocData::Read()
//EditorList //EditorList
m_DocInfo.nNumEditedBy = m_pObjStrm->QuickReaduInt16(); m_DocInfo.nNumEditedBy = m_pObjStrm->QuickReaduInt16();
LwpAtomHolder* pCDLNList = new LwpAtomHolder[m_DocInfo.nNumEditedBy]; std::unique_ptr<LwpAtomHolder[]> pCDLNList(new LwpAtomHolder[m_DocInfo.nNumEditedBy]);
LwpAtomHolder* pEditorList = new LwpAtomHolder[m_DocInfo.nNumEditedBy]; std::unique_ptr<LwpAtomHolder[]> pEditorList(new LwpAtomHolder[m_DocInfo.nNumEditedBy]);
sal_uInt16 i = 0; sal_uInt16 i = 0;
for ( i = 0; i < m_DocInfo.nNumEditedBy; i++) for ( i = 0; i < m_DocInfo.nNumEditedBy; i++)
{ {
...@@ -131,8 +131,8 @@ void LwpDocData::Read() ...@@ -131,8 +131,8 @@ void LwpDocData::Read()
m_pObjStrm->SkipExtra(); m_pObjStrm->SkipExtra();
delete [] pCDLNList; pCDLNList.reset();
delete [] pEditorList; pEditorList.reset();
//doc control //doc control
//cGreeting //cGreeting
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
* Base64 tool. * Base64 tool.
************************************************************************/ ************************************************************************/
#include <string.h> #include <string.h>
#include <memory>
#include "xfbase64.hxx" #include "xfbase64.hxx"
const sal_Char aBase64EncodeTable[] = const sal_Char aBase64EncodeTable[] =
...@@ -95,7 +96,7 @@ inline void Encode_(const sal_uInt8 *src, sal_Char* dest) ...@@ -95,7 +96,7 @@ inline void Encode_(const sal_uInt8 *src, sal_Char* dest)
*/ */
OUString XFBase64::Encode(sal_uInt8 const *buf, sal_Int32 len) OUString XFBase64::Encode(sal_uInt8 const *buf, sal_Int32 len)
{ {
sal_Char *buffer; std::unique_ptr<sal_Char[]> buffer;
sal_Int32 nNeeded; sal_Int32 nNeeded;
sal_Int32 cycles = len/3; sal_Int32 cycles = len/3;
sal_Int32 remain = len%3; sal_Int32 remain = len%3;
...@@ -104,31 +105,29 @@ OUString XFBase64::Encode(sal_uInt8 const *buf, sal_Int32 len) ...@@ -104,31 +105,29 @@ OUString XFBase64::Encode(sal_uInt8 const *buf, sal_Int32 len)
nNeeded = cycles*4; nNeeded = cycles*4;
else else
nNeeded = (cycles+1)*4; nNeeded = (cycles+1)*4;
buffer = new sal_Char[nNeeded+1]; buffer.reset(new sal_Char[nNeeded+1]);
memset(buffer, 0, nNeeded+1); memset(buffer.get(), 0, nNeeded+1);
for( sal_Int32 i=0; i<cycles; i++ ) for( sal_Int32 i=0; i<cycles; i++ )
Encode_(buf+i*3,buffer+i*4); Encode_(buf+i*3,buffer.get()+i*4);
sal_uInt8 last[3]; sal_uInt8 last[3];
if( remain == 1 ) if( remain == 1 )
{ {
last[0] = buf[len-1]; last[0] = buf[len-1];
last[1] = last[2] = 0; last[1] = last[2] = 0;
Encode_(last,buffer+nNeeded+1-5); Encode_(last,buffer.get()+nNeeded+1-5);
} }
else if( remain == 2 ) else if( remain == 2 )
{ {
last[0] = buf[len-2]; last[0] = buf[len-2];
last[1] = buf[len-1]; last[1] = buf[len-1];
last[2] = 0; last[2] = 0;
Encode_(last,buffer+nNeeded+1-5); Encode_(last,buffer.get()+nNeeded+1-5);
} }
OUString str = OUString::createFromAscii(buffer); OUString str = OUString::createFromAscii(buffer.get());
delete[] buffer;
return str; return str;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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