summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-07-10 09:47:35 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-07-10 11:31:17 +0200
commit7e73c033a128403bdeeb8be323e43ba2c7c8f8b4 (patch)
tree40b82e097eb17cdc994e29024fba21a1c0587205 /hwpfilter
parent365cf17a375f96789ae0b175ebaec80c6c9e8373 (diff)
loplugin:useuniqueptr in hwpfilter
Change-Id: Id271fdb59cb0dedf2f180879d2116d11e45d68b3 Reviewed-on: https://gerrit.libreoffice.org/39739 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hbox.cxx15
-rw-r--r--hwpfilter/source/hbox.h17
-rw-r--r--hwpfilter/source/htags.cxx15
-rw-r--r--hwpfilter/source/htags.h6
-rw-r--r--hwpfilter/source/hwpread.cxx26
-rw-r--r--hwpfilter/source/hwpreader.cxx72
6 files changed, 67 insertions, 84 deletions
diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx
index 9ad331945798..124ebabd28b8 100644
--- a/hwpfilter/source/hbox.cxx
+++ b/hwpfilter/source/hbox.cxx
@@ -86,23 +86,11 @@ SkipData::~SkipData()
FieldCode::FieldCode()
: HBox(CH_FIELD)
, location_info(0)
- , str1(nullptr)
- , str2(nullptr)
- , str3(nullptr)
- , m_pDate(nullptr)
{
- reserved1 = new char[4];
- reserved2 = new char[22];
}
FieldCode::~FieldCode()
{
- delete[] str1;
- delete[] str2;
- delete[] str3;
- delete[] reserved1;
- delete[] reserved2;
- delete m_pDate;
}
// book mark(6)
@@ -359,8 +347,6 @@ TxtBox::TxtBox()
TxtBox::~TxtBox()
{
- delete[] cell;
-
for (auto& entry : plists)
{
std::list < HWPPara* >::iterator it = entry.begin();
@@ -398,7 +384,6 @@ Picture::Picture()
Picture::~Picture()
{
- delete[]follow;
if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo);
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
index 8824a0911ded..5959e7def4d5 100644
--- a/hwpfilter/source/hbox.h
+++ b/hwpfilter/source/hbox.h
@@ -22,6 +22,7 @@
#include <sal/config.h>
+#include <array>
#include <list>
#include <memory>
@@ -81,14 +82,14 @@ struct DateCode;
struct FieldCode : public HBox
{
uchar type[2]; /* 2/0 - Formula, 3/0-document summary, 3/1 Personal Information, 3/2-creation date, 4/0-pressing mold */
- char *reserved1;
+ std::array<char, 4> reserved1;
unsigned short location_info; /* 0 - End code, 1 - start code */
- char *reserved2;
- hchar *str1;
- hchar *str2;
- hchar *str3;
+ std::array<char, 22> reserved2;
+ std::unique_ptr<hchar[]> str1;
+ std::unique_ptr<hchar[]> str2;
+ std::unique_ptr<hchar[]> str3;
- DateCode *m_pDate;
+ std::unique_ptr<DateCode> m_pDate;
FieldCode();
virtual ~FieldCode() override;
@@ -357,7 +358,7 @@ struct TxtBox: public FBox
*/
short protect; //1=size lock
- Cell *cell;
+ std::unique_ptr<Cell[]> cell;
Table *m_pTable;
/**
* Paragraph list
@@ -629,7 +630,7 @@ struct Picture: public FBox
/**
* It's for the Drawing object
*/
- unsigned char *follow; /* When the type of image is drawing, gives additional information. */
+ std::unique_ptr<unsigned char[]> follow; /* When the type of image is drawing, gives additional information. */
bool ishyper;
diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx
index 3f212b4e9b32..ddd9438e0358 100644
--- a/hwpfilter/source/htags.cxx
+++ b/hwpfilter/source/htags.cxx
@@ -47,17 +47,14 @@ void HyperText::Read(HWPFile & hwpf)
EmPicture::EmPicture(size_t tsize)
: size(tsize >= 32 ? tsize - 32 : 0)
{
- if (size == 0)
- data = nullptr;
- else
- data = new uchar[size];
+ if (size != 0)
+ data.reset( new uchar[size] );
}
#ifdef _WIN32
#define unlink _unlink
#endif
EmPicture::~EmPicture()
{
- delete[] data;
};
bool EmPicture::Read(HWPFile & hwpf)
@@ -69,7 +66,7 @@ bool EmPicture::Read(HWPFile & hwpf)
name[0] = 'H';
name[1] = 'W';
name[2] = 'P';
- return hwpf.ReadBlock(data, size) != 0;
+ return hwpf.ReadBlock(data.get(), size) != 0;
}
@@ -81,7 +78,7 @@ OlePicture::OlePicture(int tsize)
if (size <= 0)
return;
#ifndef _WIN32
- pis = new char[size];
+ pis.reset( new char[size] );
#endif
};
@@ -90,8 +87,6 @@ OlePicture::~OlePicture()
#ifdef _WIN32
if( pis )
pis->Release();
-#else
- delete[] pis;
#endif
};
@@ -135,7 +130,7 @@ void OlePicture::Read(HWPFile & hwpf)
}
unlink(tname);
#else
- if (pis == nullptr || hwpf.ReadBlock(pis, size) == 0)
+ if (pis == nullptr || hwpf.ReadBlock(pis.get(), size) == 0)
return;
#endif
}
diff --git a/hwpfilter/source/htags.h b/hwpfilter/source/htags.h
index 292897b47bcd..5d044ee8666e 100644
--- a/hwpfilter/source/htags.h
+++ b/hwpfilter/source/htags.h
@@ -20,6 +20,8 @@
#ifndef INCLUDED_HWPFILTER_SOURCE_HTAGS_H
#define INCLUDED_HWPFILTER_SOURCE_HTAGS_H
+#include <memory>
+
class HWPFile;
/**
* @short Embedded image
@@ -29,7 +31,7 @@ struct EmPicture
size_t size;
char name[16];
char type[16];
- uchar *data;
+ std::unique_ptr<uchar[]> data;
explicit EmPicture(size_t size);
~EmPicture(void);
@@ -58,7 +60,7 @@ struct OlePicture
#ifdef _WIN32
IStorage *pis;
#else
- char *pis;
+ std::unique_ptr<char[]> pis;
#endif
explicit OlePicture(int tsize);
~OlePicture(void);
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx
index 90564df487b9..69b09ebc42d8 100644
--- a/hwpfilter/source/hwpread.cxx
+++ b/hwpfilter/source/hwpread.cxx
@@ -71,9 +71,9 @@ bool FieldCode::Read(HWPFile & hwpf)
hwpf.Read4b(&size, 1);
hwpf.Read2b(&dummy, 1);
hwpf.Read1b(&type, 2);
- hwpf.Read4b(reserved1, 1);
+ hwpf.Read4b(reserved1.data(), 1);
hwpf.Read2b(&location_info, 1);
- hwpf.Read1b(reserved2, 22);
+ hwpf.Read1b(reserved2.data(), 22);
hwpf.Read4b(&len1, 1);
hwpf.Read4b(&len2, 1);
hwpf.Read4b(&len3, 1);
@@ -83,17 +83,17 @@ bool FieldCode::Read(HWPFile & hwpf)
uint const len2_ = ((len2 > 1024) ? 1024 : len2) / sizeof(hchar);
uint const len3_ = ((len3 > 1024) ? 1024 : len3) / sizeof(hchar);
- str1 = new hchar[len1_ ? len1_ : 1];
- str2 = new hchar[len2_ ? len2_ : 1];
- str3 = new hchar[len3_ ? len3_ : 1];
+ str1.reset( new hchar[len1_ ? len1_ : 1] );
+ str2.reset( new hchar[len2_ ? len2_ : 1] );
+ str3.reset( new hchar[len3_ ? len3_ : 1] );
- hwpf.Read2b(str1, len1_);
+ hwpf.Read2b(str1.get(), len1_);
hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
str1[len1_ ? (len1_ - 1) : 0] = 0;
- hwpf.Read2b(str2, len2_);
+ hwpf.Read2b(str2.get(), len2_);
hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
str2[len2_ ? (len2_ - 1) : 0] = 0;
- hwpf.Read2b(str3, len3_);
+ hwpf.Read2b(str3.get(), len3_);
hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
str3[len3_ ? (len3_ - 1) : 0] = 0;
@@ -107,7 +107,7 @@ bool FieldCode::Read(HWPFile & hwpf)
pDate->format[i] = str3[i];
}
hwpf.AddDateFormat(pDate);
- m_pDate = pDate;
+ m_pDate.reset( pDate );
}
return true;
@@ -285,7 +285,7 @@ bool TxtBox::Read(HWPFile & hwpf)
return hwpf.SetState(HWP_InvalidFileFormat);
}
- cell = ::comphelper::newArray_null<Cell>(ncell);
+ cell.reset( ::comphelper::newArray_null<Cell>(ncell) );
if (!cell) {
return hwpf.SetState(HWP_InvalidFileFormat);
}
@@ -431,12 +431,12 @@ bool Picture::Read(HWPFile & hwpf)
if (follow_block_size != 0)
{
- follow = new unsigned char[follow_block_size];
+ follow.reset( new unsigned char[follow_block_size] );
- hwpf.Read1b(follow, follow_block_size);
+ hwpf.Read1b(follow.get(), follow_block_size);
if (pictype == PICTYPE_DRAW)
{
- hmem = new HMemIODev(reinterpret_cast<char *>(follow), follow_block_size);
+ hmem = new HMemIODev(reinterpret_cast<char *>(follow.get()), follow_block_size);
LoadDrawingObjectBlock(this);
style.cell = picinfo.picdraw.hdo;
delete hmem;
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index eea0b5eb8697..3c6e1543cec8 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -541,7 +541,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
if( (fd = open( filename , O_CREAT | O_WRONLY , 0666)) >= 0 )
#endif
{
- size_t nWritten = write(fd, emp->data, emp->size);
+ size_t nWritten = write(fd, emp->data.get(), emp->size);
OSL_VERIFY(nWritten == emp->size);
close(fd);
}
@@ -2961,7 +2961,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
firstspace = 1;
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
- field = hbox->str3;
+ field = hbox->str3.get();
}
else{
makeFieldCode(str, hbox);
@@ -3152,92 +3152,92 @@ void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
/* Document Summary */
else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
{
- if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "title")
+ if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "title")
{
rstartEl( "text:title", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:title" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "subject")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "subject")
{
rstartEl( "text:subject", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:subject" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "author")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "author")
{
rstartEl( "text:author-name", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:author-name" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "keywords")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "keywords")
{
rstartEl( "text:keywords", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:keywords" );
}
}
/* Personal Information */
else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
{
- if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "User")
+ if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "User")
{
rstartEl( "text:sender-lastname", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-lastname" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Company")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Company")
{
rstartEl( "text:sender-company", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-company" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Position")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Position")
{
rstartEl( "text:sender-title", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-title" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Division")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Division")
{
rstartEl( "text:sender-position", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-position" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Fax")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Fax")
{
rstartEl( "text:sender-fax", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-fax" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Pager")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Pager")
{
rstartEl( "text:phone-private", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:phone-private" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "E-mail")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "E-mail")
{
rstartEl( "text:sender-email", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-email" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Zipcode(office)")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Zipcode(office)")
{
rstartEl( "text:sender-postal-code", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-postal-code" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Phone(office)")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Phone(office)")
{
rstartEl( "text:sender-phone-work", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-phone-work" );
}
- else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3))) == "Address(office)")
+ else if (OUString(reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get()))) == "Address(office)")
{
rstartEl( "text:sender-street", mxList.get() );
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:sender-street" );
}
@@ -3249,7 +3249,7 @@ void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
ascii(Int2Str(hbox->m_pDate->key, "N%d", buf)));
rstartEl( "text:creation-date", mxList.get() );
mxList->clear();
- rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2)) );
+ rchars( reinterpret_cast<sal_Unicode const *>(hconv(hbox->str2.get())) );
rendEl( "text:creation-date" );
}
}
@@ -3827,16 +3827,16 @@ void HwpReader::makePicture(Picture * hbox)
padd("xlink:type", sXML_CDATA, "simple");
#ifdef _WIN32
if( hbox->follow[4] != 0 )
- padd("xlink:href", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(hbox->follow + 4).c_str())));
+ padd("xlink:href", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(hbox->follow.get() + 4).c_str())));
else
- padd("xlink:href", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(hbox->follow + 5).c_str())));
+ padd("xlink:href", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(hbox->follow.get() + 5).c_str())));
#else
if( hbox->follow[4] != 0 )
padd("xlink:href", sXML_CDATA,
- reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow + 4)).c_str())).c_str())));
+ reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.get() + 4)).c_str())).c_str())));
else
padd("xlink:href", sXML_CDATA,
- reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow + 5)).c_str())).c_str())));
+ reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.get() + 5)).c_str())).c_str())));
#endif
rstartEl("draw:a", mxList.get());
mxList->clear();
@@ -3911,7 +3911,7 @@ void HwpReader::makePicture(Picture * hbox)
EmPicture *emp = hwpfile.GetEmPicture(hbox);
if( emp )
{
- std::shared_ptr<char> pStr(base64_encode_string( emp->data, emp->size ), Free<char>());
+ std::shared_ptr<char> pStr(base64_encode_string( emp->data.get(), emp->size ), Free<char>());
rchars(ascii(pStr.get()));
}
}