aboutsummaryrefslogtreecommitdiff
path: root/pdf-simple-sign.cpp
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-10-03 22:46:38 +0200
committerPřemysl Janouch <p@janouch.name>2018-10-03 22:47:46 +0200
commit4c7853c951eeab3d27be09e93dde321216a49287 (patch)
treef422ec952ebc5efbf317b880b531b773689ccbcc /pdf-simple-sign.cpp
parentc77a9c052a8db7493935bd807ed1308aea149473 (diff)
downloadpdf-simple-sign-4c7853c951eeab3d27be09e93dde321216a49287.tar.gz
pdf-simple-sign-4c7853c951eeab3d27be09e93dde321216a49287.tar.xz
pdf-simple-sign-4c7853c951eeab3d27be09e93dde321216a49287.zip
Try to return the innermost error message
Improving debugging experience.
Diffstat (limited to 'pdf-simple-sign.cpp')
-rw-r--r--pdf-simple-sign.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/pdf-simple-sign.cpp b/pdf-simple-sign.cpp
index 89b29a4..e18c058 100644
--- a/pdf-simple-sign.cpp
+++ b/pdf-simple-sign.cpp
@@ -353,6 +353,12 @@ public:
// -------------------------------------------------------------------------------------------------
+/// If the object is an error, forward its message, otherwise return err.
+static std::string pdf_error(const pdf_object& o, const char* err) {
+ if (o.type != pdf_object::END || o.string.empty()) return err;
+ return o.string;
+}
+
pdf_object pdf_updater::parse_obj(pdf_lexer& lex, std::vector<pdf_object>& stack) const {
if (stack.size() < 2)
return {pdf_object::END, "missing object ID pair"};
@@ -370,7 +376,7 @@ pdf_object pdf_updater::parse_obj(pdf_lexer& lex, std::vector<pdf_object>& stack
while (1) {
auto object = parse(lex, obj.array);
if (object.type == pdf_object::END)
- return {pdf_object::END, "object doesn't end"};
+ return {pdf_object::END, pdf_error(object, "object doesn't end")};
if (object.type == pdf_object::KEYWORD && object.string == "endobj")
break;
obj.array.push_back(std::move(object));
@@ -408,7 +414,7 @@ pdf_object pdf_updater::parse(pdf_lexer& lex, std::vector<pdf_object>& stack) co
while (1) {
auto object = parse(lex, array);
if (object.type == pdf_object::END)
- return {pdf_object::END, "array doesn't end"};
+ return {pdf_object::END, pdf_error(object, "array doesn't end")};
if (object.type == pdf_object::E_ARRAY)
break;
array.push_back(std::move(object));
@@ -421,7 +427,7 @@ pdf_object pdf_updater::parse(pdf_lexer& lex, std::vector<pdf_object>& stack) co
while (1) {
auto object = parse(lex, array);
if (object.type == pdf_object::END)
- return {pdf_object::END, "dictionary doesn't end"};
+ return {pdf_object::END, pdf_error(object, "dictionary doesn't end")};
if (object.type == pdf_object::E_DICT)
break;
array.push_back(std::move(object));
@@ -459,7 +465,7 @@ std::string pdf_updater::load_xref(pdf_lexer& lex, std::set<uint>& loaded_entrie
while (1) {
auto object = parse(lex, throwaway_stack);
if (object.type == pdf_object::END)
- return "unexpected EOF while looking for the trailer";
+ return pdf_error(object, "unexpected EOF while looking for the trailer");
if (object.type == pdf_object::KEYWORD && object.string == "trailer")
break;
@@ -529,7 +535,7 @@ std::string pdf_updater::initialize() {
auto trailer = parse(lex, throwaway_stack);
if (trailer.type != pdf_object::DICT)
- return "invalid trailer dictionary";
+ return pdf_error(trailer, "invalid trailer dictionary");
if (loaded_xrefs.empty())
this->trailer = trailer.dict;
loaded_xrefs.insert(xref_offset);