Catch exceptions as const references (fixes #236)

This fix allows qpdf to compile/test cleanly with gcc 8.
This commit is contained in:
Jay Berkenbilt 2018-08-12 21:57:52 -04:00
parent 3d6615b276
commit a2f62935b3
5 changed files with 14 additions and 14 deletions

View File

@ -77,7 +77,7 @@ int main(int argc, char* argv[])
{ {
process(whoami, argv[1], argv[2]); process(whoami, argv[1], argv[2]);
} }
catch (std::exception e) catch (std::exception const& e)
{ {
std::cerr << whoami << ": exception: " << e.what() << std::endl; std::cerr << whoami << ": exception: " << e.what() << std::endl;
return 2; return 2;

View File

@ -421,7 +421,7 @@ MD5::checkFileChecksum(char const* const checksum,
std::string actual_checksum = getFileChecksum(filename, up_to_size); std::string actual_checksum = getFileChecksum(filename, up_to_size);
result = (checksum == actual_checksum); result = (checksum == actual_checksum);
} }
catch (std::runtime_error) catch (std::runtime_error const&)
{ {
// Ignore -- return false // Ignore -- return false
} }

View File

@ -26,7 +26,7 @@ void test_to_number(char const* str, int_T wanted, bool error,
result = fn(str); result = fn(str);
worked = (wanted == result); worked = (wanted == result);
} }
catch (std::runtime_error) catch (std::runtime_error const&)
{ {
threw = true; threw = true;
} }
@ -247,7 +247,7 @@ void same_file_test()
fclose(QUtil::safe_fopen("qutil.out", "r")); fclose(QUtil::safe_fopen("qutil.out", "r"));
fclose(QUtil::safe_fopen("other-file", "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" std::cout << "same_file_test expects to have qutil.out and other-file"
" exist in the current directory\n"; " exist in the current directory\n";

View File

@ -773,7 +773,7 @@ static std::vector<int> parse_numrange(char const* range, int max,
} }
} }
} }
catch (std::runtime_error e) catch (std::runtime_error const& e)
{ {
if (throw_error) 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); parse_numrange(range.c_str(), 0, true);
range_valid = true; range_valid = true;
} }
catch (std::runtime_error) catch (std::runtime_error const&)
{ {
// ignore // ignore
} }

View File

@ -717,7 +717,7 @@ void runtest(int n, char const* filename1, char const* arg2)
// Do it wrong first... // Do it wrong first...
pdf.replaceObject(qdict.getObjGen(), qdict); pdf.replaceObject(qdict.getObjGen(), qdict);
} }
catch (std::logic_error) catch (std::logic_error const&)
{ {
std::cout << "caught logic error as expected" << std::endl; 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(); res2.unparseResolved();
std::cout << "oops -- didn't throw" << std::endl; 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; std::cout << "logic error: " << e.what() << std::endl;
} }
@ -1012,7 +1012,7 @@ void runtest(int n, char const* filename1, char const* arg2)
res2.makeDirect(); res2.makeDirect();
std::cout << "oops -- didn't throw" << std::endl; 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; 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")); pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest"));
std::cout << "oops -- didn't throw" << std::endl; 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; 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)); pdf.copyForeignObject(QPDFObjectHandle::newInteger(1));
std::cout << "oops -- didn't throw" << std::endl; 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; std::cout << "logic error: " << e.what() << std::endl;
} }
@ -1139,7 +1139,7 @@ void runtest(int n, char const* filename1, char const* arg2)
w.write(); w.write();
std::cout << "oops -- didn't throw" << std::endl; 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; 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"); QPDFObjectHandle::parse("[1 0 R]", "indirect test");
std::cout << "oops -- didn't throw" << std::endl; 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::cout << "logic error parsing indirect: " << e.what()
<< std::endl; << std::endl;
@ -1195,7 +1195,7 @@ void runtest(int n, char const* filename1, char const* arg2)
QPDFObjectHandle::parse("0 trailing", "trailing test"); QPDFObjectHandle::parse("0 trailing", "trailing test");
std::cout << "oops -- didn't throw" << std::endl; 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::cout << "trailing data: " << e.what()
<< std::endl; << std::endl;