[poppler] 5 commits - utils/pdffonts.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Nov 7 13:53:16 UTC 2019
utils/pdffonts.cc | 40 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
New commits:
commit 409121ea8b65189bcc2c8541297cd4b51c69d322
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Oct 29 10:35:58 2019 +0100
Do not include string.h, it is not used
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 8708d879..fe98b8d1 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -31,7 +31,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
-#include <string.h>
#include <math.h>
#include <memory>
#include <string>
commit 1601933e08e72df51e3ea923a8a34c198a29e518
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Oct 29 10:34:22 2019 +0100
Use std::unique_ptr for passwords
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 652a7759..8708d879 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -93,7 +93,7 @@ static const ArgDesc argDesc[] = {
};
int main(int argc, char *argv[]) {
- GooString *ownerPW, *userPW;
+ std::unique_ptr<GooString> ownerPW, userPW;
bool ok;
int exitCode;
@@ -124,24 +124,14 @@ int main(int argc, char *argv[]) {
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = std::make_unique<GooString>(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = std::make_unique<GooString>(userPassword);
}
- auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW, userPW));
+ auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW.get(), userPW.get()));
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
exitCode = 1;
goto err1;
commit f37f1565c0aa4efec2eaa912397f61952f5c3c7d
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Oct 29 10:30:19 2019 +0100
Use std::unique_ptr for PDFDoc
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index b940d6ac..652a7759 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -33,6 +33,7 @@
#include <stddef.h>
#include <string.h>
#include <math.h>
+#include <memory>
#include <string>
#include "parseargs.h"
#include "goo/GooString.h"
@@ -92,7 +93,6 @@ static const ArgDesc argDesc[] = {
};
int main(int argc, char *argv[]) {
- PDFDoc *doc;
GooString *ownerPW, *userPW;
bool ok;
int exitCode;
@@ -134,7 +134,7 @@ int main(int argc, char *argv[]) {
userPW = nullptr;
}
- doc = PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW, userPW);
+ auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW, userPW));
if (userPW) {
delete userPW;
@@ -163,7 +163,7 @@ int main(int argc, char *argv[]) {
// get the fonts
{
- FontInfoScanner scanner(doc, firstPage - 1);
+ FontInfoScanner scanner(doc.get(), firstPage - 1);
const std::vector<FontInfo*> fonts = scanner.scan(lastPage - firstPage + 1);
if (showSubst) {
@@ -212,7 +212,6 @@ int main(int argc, char *argv[]) {
exitCode = 0;
err1:
- delete doc;
delete globalParams;
return exitCode;
commit d1f627fefd6dc84bd37064a421fc0095dbfd21c0
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Oct 29 10:25:59 2019 +0100
Use std::string for the filename
... and create it on the stack rather than on the heap.
Makes the code more readable.
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 87ea9e0b..b940d6ac 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -33,6 +33,7 @@
#include <stddef.h>
#include <string.h>
#include <math.h>
+#include <string>
#include "parseargs.h"
#include "goo/GooString.h"
#include "goo/gmem.h"
@@ -92,7 +93,6 @@ static const ArgDesc argDesc[] = {
int main(int argc, char *argv[]) {
PDFDoc *doc;
- GooString *fileName;
GooString *ownerPW, *userPW;
bool ok;
int exitCode;
@@ -113,7 +113,11 @@ int main(int argc, char *argv[]) {
exitCode = 0;
return exitCode;
}
- fileName = new GooString(argv[1]);
+
+ std::string fileName(argv[1]);
+ if (fileName == "-") {
+ fileName = "fd://0";
+ }
// read config file
globalParams = new GlobalParams();
@@ -129,13 +133,8 @@ int main(int argc, char *argv[]) {
} else {
userPW = nullptr;
}
- if (fileName->cmp("-") == 0) {
- delete fileName;
- fileName = new GooString("fd://0");
- }
- doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- delete fileName;
+ doc = PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW, userPW);
if (userPW) {
delete userPW;
commit d89faa0f8ceddb81fc4430dec08023ac987ad0e4
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Oct 29 10:24:48 2019 +0100
Remove the 'err0' error handling goto target
It is used only once, and removing it allows me to move
variable declarations around more freely.
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 24eb5038..87ea9e0b 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
}
if (printVersion || printHelp)
exitCode = 0;
- goto err0;
+ return exitCode;
}
fileName = new GooString(argv[1]);
@@ -215,7 +215,6 @@ int main(int argc, char *argv[]) {
err1:
delete doc;
delete globalParams;
- err0:
return exitCode;
}
More information about the poppler
mailing list