summaryrefslogtreecommitdiff
path: root/poppler
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 /poppler
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 'poppler')
-rw-r--r--poppler/UnicodeMap.cc15
-rw-r--r--poppler/UnicodeMap.h4
2 files changed, 10 insertions, 9 deletions
diff --git a/poppler/UnicodeMap.cc b/poppler/UnicodeMap.cc
index 6125294b..6e7e467b 100644
--- a/poppler/UnicodeMap.cc
+++ b/poppler/UnicodeMap.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2010 Jakub Wilk <jwilk@jwilk.net>
-// Copyright (C) 2017, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2017 Jean Ghali <jghali@libertysurf.fr>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
@@ -71,7 +71,7 @@ UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
map = new UnicodeMap(encodingNameA->copy());
size = 8;
- map->ranges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange));
+ UnicodeMapRange *customRanges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange));
eMapsSize = 0;
line = 1;
@@ -86,10 +86,10 @@ UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
if (nBytes <= 4) {
if (map->len == size) {
size *= 2;
- map->ranges = (UnicodeMapRange *)
- greallocn(map->ranges, size, sizeof(UnicodeMapRange));
+ customRanges = (UnicodeMapRange *)
+ greallocn(customRanges, size, sizeof(UnicodeMapRange));
}
- range = &map->ranges[map->len];
+ range = &customRanges[map->len];
sscanf(tok1, "%x", &range->start);
sscanf(tok2, "%x", &range->end);
sscanf(tok3, "%x", &range->code);
@@ -125,6 +125,7 @@ UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
fclose(f);
+ map->ranges = customRanges;
return map;
}
@@ -144,7 +145,7 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
encodingName = new GooString(encodingNameA);
unicodeOut = unicodeOutA;
kind = unicodeMapResident;
- ranges = const_cast<UnicodeMapRange*>(rangesA);
+ ranges = rangesA;
len = lenA;
eMaps = nullptr;
eMapsLen = 0;
@@ -165,7 +166,7 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
UnicodeMap::~UnicodeMap() {
delete encodingName;
if (kind == unicodeMapUser && ranges) {
- gfree(ranges);
+ gfree(const_cast<UnicodeMapRange *>(ranges));
}
if (eMaps) {
gfree(eMaps);
diff --git a/poppler/UnicodeMap.h b/poppler/UnicodeMap.h
index 74f6ded0..17f1d59c 100644
--- a/poppler/UnicodeMap.h
+++ b/poppler/UnicodeMap.h
@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
-// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2018, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2019 Volker Krause <vkrause@kde.org>
//
@@ -104,7 +104,7 @@ private:
UnicodeMapKind kind;
bool unicodeOut;
union {
- UnicodeMapRange *ranges; // (user, resident)
+ const UnicodeMapRange *ranges; // (user, resident)
UnicodeMapFunc func; // (func)
};
int len; // (user, resident)