diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-11-29 13:31:05 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-11-29 13:42:36 +0100 |
commit | 720ce9e8f333ba3911fa8003f08fd8813c19181a (patch) | |
tree | 158d7a6c4030f5b468c99f39b875cc1aaadd9c4c | |
parent | ac17308cf6cd6ea51cfbffdc898f0b67c89ae388 (diff) | |
download | qpdf-720ce9e8f333ba3911fa8003f08fd8813c19181a.tar.zst |
Improve testing and error handling around operating before processing
-rw-r--r-- | include/qpdf/qpdf-c.h | 4 | ||||
-rw-r--r-- | libqpdf/QPDF.cc | 6 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/test73.out | 3 | ||||
-rw-r--r-- | qpdf/test_driver.cc | 10 |
4 files changed, 19 insertions, 4 deletions
diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index cf32976f..886e521f 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -113,7 +113,9 @@ extern "C" { char const* qpdf_get_qpdf_version(); /* Returns dynamically allocated qpdf_data pointer; must be freed - * by calling qpdf_cleanup. + * by calling qpdf_cleanup. You must call qpdf_read or one of the + * other qpdf_read_* functions before calling any function that + * would need to operate on the PDF file. */ QPDF_DLL qpdf_data qpdf_init(); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 4c9296ea..c81aede0 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -85,8 +85,10 @@ class InvalidInputSource: public InputSource private: void throwException() { - throw std::runtime_error( - "QPDF operation attempted after closing input source"); + throw std::logic_error( + "QPDF operation attempted on a QPDF object with no input source." + " QPDF operations are invalid before processFile (or another" + " process method) or after closeInputSource"); } }; diff --git a/qpdf/qtest/qpdf/test73.out b/qpdf/qtest/qpdf/test73.out index 435189fd..b23c4c00 100644 --- a/qpdf/qtest/qpdf/test73.out +++ b/qpdf/qtest/qpdf/test73.out @@ -1,2 +1,3 @@ -WARNING: closed input source: object 1/0: error reading object: QPDF operation attempted after closing input source +getRoot: attempted to dereference an uninitialized QPDFObjectHandle +WARNING: closed input source: object 1/0: error reading object: QPDF operation attempted on a QPDF object with no input source. QPDF operations are invalid before processFile (or another process method) or after closeInputSource closed input source: unable to find /Root dictionary diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 1d995bb7..7d5b2ece 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -2715,6 +2715,16 @@ void runtest(int n, char const* filename1, char const* arg2) } else if (n == 73) { + try + { + QPDF pdf2; + pdf2.getRoot(); + } + catch (std::exception& e) + { + std::cerr << "getRoot: " << e.what() << std::endl; + } + pdf.closeInputSource(); pdf.getRoot().getKey("/Pages").unparseResolved(); } |