From a2f62935b35aebe68a5a2f7e729ae4bb8734cfc7 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 12 Aug 2018 21:57:52 -0400 Subject: [PATCH] Catch exceptions as const references (fixes #236) This fix allows qpdf to compile/test cleanly with gcc 8. --- examples/pdf-split-pages.cc | 2 +- libqpdf/MD5.cc | 2 +- libtests/qutil.cc | 4 ++-- qpdf/qpdf.cc | 4 ++-- qpdf/test_driver.cc | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/pdf-split-pages.cc b/examples/pdf-split-pages.cc index b65f96ee..aa089e5a 100644 --- a/examples/pdf-split-pages.cc +++ b/examples/pdf-split-pages.cc @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { process(whoami, argv[1], argv[2]); } - catch (std::exception e) + catch (std::exception const& e) { std::cerr << whoami << ": exception: " << e.what() << std::endl; return 2; diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc index 0504e2d4..275567da 100644 --- a/libqpdf/MD5.cc +++ b/libqpdf/MD5.cc @@ -421,7 +421,7 @@ MD5::checkFileChecksum(char const* const checksum, std::string actual_checksum = getFileChecksum(filename, up_to_size); result = (checksum == actual_checksum); } - catch (std::runtime_error) + catch (std::runtime_error const&) { // Ignore -- return false } diff --git a/libtests/qutil.cc b/libtests/qutil.cc index a7479fb5..78c52156 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -26,7 +26,7 @@ void test_to_number(char const* str, int_T wanted, bool error, result = fn(str); worked = (wanted == result); } - catch (std::runtime_error) + catch (std::runtime_error const&) { threw = true; } @@ -247,7 +247,7 @@ void same_file_test() fclose(QUtil::safe_fopen("qutil.out", "r")); fclose(QUtil::safe_fopen("other-file", "r")); } - catch (std::exception) + catch (std::exception const&) { std::cout << "same_file_test expects to have qutil.out and other-file" " exist in the current directory\n"; diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 9655049f..158bb993 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -773,7 +773,7 @@ static std::vector parse_numrange(char const* range, int max, } } } - catch (std::runtime_error e) + catch (std::runtime_error const& e) { if (throw_error) { @@ -1372,7 +1372,7 @@ static void parse_rotation_parameter(Options& o, std::string const& parameter) parse_numrange(range.c_str(), 0, true); range_valid = true; } - catch (std::runtime_error) + catch (std::runtime_error const&) { // ignore } diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index c167b643..14a317ba 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -717,7 +717,7 @@ void runtest(int n, char const* filename1, char const* arg2) // Do it wrong first... pdf.replaceObject(qdict.getObjGen(), qdict); } - catch (std::logic_error) + catch (std::logic_error const&) { std::cout << "caught logic error as expected" << std::endl; } @@ -1003,7 +1003,7 @@ void runtest(int n, char const* filename1, char const* arg2) res2.unparseResolved(); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error: " << e.what() << std::endl; } @@ -1012,7 +1012,7 @@ void runtest(int n, char const* filename1, char const* arg2) res2.makeDirect(); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error: " << e.what() << std::endl; } @@ -1109,7 +1109,7 @@ void runtest(int n, char const* filename1, char const* arg2) pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest")); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error: " << e.what() << std::endl; } @@ -1118,7 +1118,7 @@ void runtest(int n, char const* filename1, char const* arg2) pdf.copyForeignObject(QPDFObjectHandle::newInteger(1)); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error: " << e.what() << std::endl; } @@ -1139,7 +1139,7 @@ void runtest(int n, char const* filename1, char const* arg2) w.write(); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error: " << e.what() << std::endl; } @@ -1185,7 +1185,7 @@ void runtest(int n, char const* filename1, char const* arg2) QPDFObjectHandle::parse("[1 0 R]", "indirect test"); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::logic_error e) + catch (std::logic_error const& e) { std::cout << "logic error parsing indirect: " << e.what() << std::endl; @@ -1195,7 +1195,7 @@ void runtest(int n, char const* filename1, char const* arg2) QPDFObjectHandle::parse("0 trailing", "trailing test"); std::cout << "oops -- didn't throw" << std::endl; } - catch (std::runtime_error e) + catch (std::runtime_error const& e) { std::cout << "trailing data: " << e.what() << std::endl;