summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel <noel.grandin@collabora.co.uk>2021-03-23 12:17:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-03-24 20:36:35 +0100
commit6c13e5a92ed4b6a10458cd5d5741ddb3d816df4e (patch)
treebf9e5062ed1a2f1c2e480535915ec420bb655591
parent4f28ca3e16de71e279fc54cd4a95e8181479c263 (diff)
convert m_pFileName to std::string
which simplifies the code and fixes a problem with using strdup(), because strdup() allocates with malloc, while unique_ptr will free it with delete[], and we'll get a mismatch error from ASAN (spotted by Mike Kaganski) Change-Id: I0f21828ef3482898b81aa3f0745b2bd855a2c286 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112980 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--vcl/inc/sft.hxx4
-rw-r--r--vcl/source/fontsubset/sft.cxx12
2 files changed, 8 insertions, 8 deletions
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index 877b94713a8f..fb43e51a174a 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -720,7 +720,7 @@ constexpr int NUM_TAGS = 17;
class VCL_DLLPUBLIC AbstractTrueTypeFont
{
- std::unique_ptr<char[]> m_pFileName;
+ std::string m_sFileName;
sal_uInt32 m_nGlyphs;
sal_uInt32 m_nHorzMetrics;
sal_uInt32 m_nVertMetrics; /* if not 0 => font has vertical metrics information */
@@ -735,7 +735,7 @@ public:
AbstractTrueTypeFont(const char* fileName = nullptr, const FontCharMapRef xCharMap = nullptr);
virtual ~AbstractTrueTypeFont();
- const char* fileName() const { return m_pFileName.get(); }
+ std::string const & fileName() const { return m_sFileName; }
sal_uInt32 glyphCount() const { return m_nGlyphs; }
sal_uInt32 glyphOffset(sal_uInt32 glyphID) const;
sal_uInt32 horzMetricCount() const { return m_nHorzMetrics; }
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 5208b46adb28..fe0f0ef1562a 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -925,9 +925,9 @@ static void GetNames(TrueTypeFont *t)
}
if ( ! t->psname )
{
- if (t->fileName())
+ if (!t->fileName().empty())
{
- const char* pReverse = t->fileName() + strlen(t->fileName());
+ const char* pReverse = t->fileName().data() + t->fileName().length();
/* take only last token of filename */
while (pReverse != t->fileName() && *pReverse != '/') pReverse--;
if(*pReverse == '/') pReverse++;
@@ -1034,7 +1034,7 @@ SFErrCodes OpenTTFontFile(const char* fname, sal_uInt32 facenum, TrueTypeFont**
if( ! *ttf )
return SFErrCodes::Memory;
- if( ! (*ttf)->fileName() )
+ if( (*ttf)->fileName().empty() )
{
ret = SFErrCodes::Memory;
goto cleanup;
@@ -1121,7 +1121,7 @@ AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontChar
, m_xCharMap(xCharMap)
{
if (pFileName)
- m_pFileName.reset(strdup(pFileName));
+ m_sFileName = pFileName;
}
AbstractTrueTypeFont::~AbstractTrueTypeFont()
@@ -1144,7 +1144,7 @@ TrueTypeFont::TrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap)
TrueTypeFont::~TrueTypeFont()
{
#if !defined(_WIN32)
- if (fileName())
+ if (!fileName().empty())
munmap(ptr, fsize);
#endif
free(psname);
@@ -1897,7 +1897,7 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf,
fprintf(outf, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver), static_cast<int>(ver & 0xFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF));
fprintf(outf, "%%%%Creator: %s %s %s\n", modname, modver, modextra);
- fprintf(outf, "%%- Font subset generated from a source font file: '%s'\n", ttf->fileName());
+ fprintf(outf, "%%- Font subset generated from a source font file: '%s'\n", ttf->fileName().data());
fprintf(outf, "%%- Original font name: %s\n", ttf->psname);
fprintf(outf, "%%- Original font family: %s\n", ttf->family);
fprintf(outf, "%%- Original font sub-family: %s\n", ttf->subfamily);