summaryrefslogtreecommitdiff
path: root/fofi
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2019-09-29 17:41:44 +0200
committerAlbert Astals Cid <aacid@kde.org>2019-09-29 17:41:44 +0200
commite702c6508e9b2e8082d99683ba933e9679608251 (patch)
tree8a1a703353d47e44e08b046b7150aa2aaf14c3c9 /fofi
parentfacb696ee9d7654b2c60f2ebe3e09d71f11d384c (diff)
Move the const_cast from assignment to free
The problem is that some of the times the pointers hold values to const tables and some others hold values to dynamic memory. Instead of const_casting the const tables when needed and holding a non const pointer, we hold a const pointer and only const cast on free if needed
Diffstat (limited to 'fofi')
-rw-r--r--fofi/FoFiType1C.cc21
-rw-r--r--fofi/FoFiType1C.h2
2 files changed, 12 insertions, 11 deletions
diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 8ecc066a..cdcef18a 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -107,7 +107,7 @@ FoFiType1C::~FoFiType1C() {
charset != fofiType1CISOAdobeCharset &&
charset != fofiType1CExpertCharset &&
charset != fofiType1CExpertSubsetCharset) {
- gfree(charset);
+ gfree(const_cast<unsigned short *>(charset));
}
}
@@ -2503,25 +2503,25 @@ bool FoFiType1C::readCharset() {
int nLeft, i, j;
if (topDict.charsetOffset == 0) {
- charset = const_cast<unsigned short*>(fofiType1CISOAdobeCharset);
+ charset = fofiType1CISOAdobeCharset;
charsetLength = sizeof(fofiType1CISOAdobeCharset) / sizeof(unsigned short);
} else if (topDict.charsetOffset == 1) {
- charset = const_cast<unsigned short*>(fofiType1CExpertCharset);
+ charset = fofiType1CExpertCharset;
charsetLength = sizeof(fofiType1CExpertCharset) / sizeof(unsigned short);
} else if (topDict.charsetOffset == 2) {
- charset = const_cast<unsigned short*>(fofiType1CExpertSubsetCharset);
+ charset = fofiType1CExpertSubsetCharset;
charsetLength = sizeof(fofiType1CExpertSubsetCharset) / sizeof(unsigned short);
} else {
- charset = (unsigned short *)gmallocn(nGlyphs, sizeof(unsigned short));
+ unsigned short *customCharset = (unsigned short *)gmallocn(nGlyphs, sizeof(unsigned short));
charsetLength = nGlyphs;
for (i = 0; i < nGlyphs; ++i) {
- charset[i] = 0;
+ customCharset[i] = 0;
}
pos = topDict.charsetOffset;
charsetFormat = getU8(pos++, &parsedOk);
if (charsetFormat == 0) {
for (i = 1; i < nGlyphs; ++i) {
- charset[i] = (unsigned short)getU16BE(pos, &parsedOk);
+ customCharset[i] = (unsigned short)getU16BE(pos, &parsedOk);
pos += 2;
if (!parsedOk) {
break;
@@ -2537,7 +2537,7 @@ bool FoFiType1C::readCharset() {
break;
}
for (j = 0; j <= nLeft && i < nGlyphs; ++j) {
- charset[i++] = (unsigned short)c++;
+ customCharset[i++] = (unsigned short)c++;
}
}
} else if (charsetFormat == 2) {
@@ -2551,16 +2551,17 @@ bool FoFiType1C::readCharset() {
break;
}
for (j = 0; j <= nLeft && i < nGlyphs; ++j) {
- charset[i++] = (unsigned short)c++;
+ customCharset[i++] = (unsigned short)c++;
}
}
}
if (!parsedOk) {
- gfree(charset);
+ gfree(customCharset);
charset = nullptr;
charsetLength = 0;
return false;
}
+ charset = customCharset;
}
return true;
}
diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h
index faae806d..ff69651a 100644
--- a/fofi/FoFiType1C.h
+++ b/fofi/FoFiType1C.h
@@ -246,7 +246,7 @@ private:
int nGlyphs;
int nFDs;
unsigned char *fdSelect;
- unsigned short *charset;
+ const unsigned short *charset;
unsigned short charsetLength;
int gsubrBias;