2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-03 15:17:29 +00:00

Improve testing and error handling around operating before processing

This commit is contained in:
Jay Berkenbilt 2021-11-29 07:31:05 -05:00
parent ac17308cf6
commit 720ce9e8f3
4 changed files with 19 additions and 4 deletions

View File

@ -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();

View File

@ -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");
}
};

View File

@ -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

View File

@ -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();
}