loplugin:useuniqueptr in HWPFont

Change-Id: Idd20e180fdd215028cf972e7ed97b37b7b9bed55
Reviewed-on: https://gerrit.libreoffice.org/49872
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2018-02-06 10:27:44 +02:00
parent 7a510effa4
commit 722d0b9882
2 changed files with 6 additions and 10 deletions

View file

@ -35,11 +35,6 @@ HWPFont::HWPFont()
HWPFont::~HWPFont()
{
for (int ii = 0; ii < NLanguage; ii++)
{
nFonts[ii] = 0;
delete[]fontnames[ii];
}
}
@ -52,7 +47,7 @@ void HWPFont::AddFont(int lang, const char *font)
nfonts = nFonts[lang];
if (MAXFONTS <= nfonts)
return;
strncpy(fontnames[lang] + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
strncpy(fontnames[lang].get() + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
nFonts[lang]++;
}
@ -63,7 +58,7 @@ const char *HWPFont::GetFontName(int lang, int id)
return nullptr;
if (id < 0 || nFonts[lang] <= id)
return nullptr;
return fontnames[lang] + id * FONTNAMELEN;
return fontnames[lang].get() + id * FONTNAMELEN;
}
@ -83,9 +78,9 @@ void HWPFont::Read(HWPFile & hwpf)
(void)hwpf.SetState(HWP_InvalidFileFormat);
return;
}
fontnames[lang] = new char[nfonts * FONTNAMELEN];
fontnames[lang].reset(new char[nfonts * FONTNAMELEN]);
memset(fontnames[lang], 0, nfonts * FONTNAMELEN);
memset(fontnames[lang].get(), 0, nfonts * FONTNAMELEN);
for (int jj = 0; jj < nfonts; jj++)
{
hwpf.ReadBlock(buffer, FONTNAMELEN);

View file

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <memory>
#define MAXFONTS 256
#define FONTNAMELEN 40
@ -42,7 +43,7 @@ class DLLEXPORT HWPFont final
/**
* list of the font family name
*/
char *fontnames[NLanguage];
std::unique_ptr<char[]> fontnames[NLanguage];
public:
HWPFont(void);