Commit b0ceea467ae3cb6c2cbecf57ae23532a951994ad
1 parent
03ea948c
Add `final` specifiers and initialize member variables.
Refactored several classes to use C++11 `final` specifiers for inheritance restrictions and added default member initializations. These changes enhance code clarity, improve safety, and ensure modern coding practices.
Showing
21 changed files
with
53 additions
and
87 deletions
include/qpdf/ClosedFileInputSource.hh
| @@ -69,9 +69,9 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource | @@ -69,9 +69,9 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource | ||
| 69 | void after(); | 69 | void after(); |
| 70 | 70 | ||
| 71 | std::string filename; | 71 | std::string filename; |
| 72 | - qpdf_offset_t offset; | 72 | + qpdf_offset_t offset{0}; |
| 73 | std::shared_ptr<FileInputSource> fis; | 73 | std::shared_ptr<FileInputSource> fis; |
| 74 | - bool stay_open; | 74 | + bool stay_open{false}; |
| 75 | }; | 75 | }; |
| 76 | 76 | ||
| 77 | #endif // QPDF_CLOSEDFILEINPUTSOURCE_HH | 77 | #endif // QPDF_CLOSEDFILEINPUTSOURCE_HH |
include/qpdf/QPDFAcroFormDocumentHelper.hh
| @@ -234,10 +234,10 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | @@ -234,10 +234,10 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | ||
| 234 | ~Members() = default; | 234 | ~Members() = default; |
| 235 | 235 | ||
| 236 | private: | 236 | private: |
| 237 | - Members(); | 237 | + Members() = default; |
| 238 | Members(Members const&) = delete; | 238 | Members(Members const&) = delete; |
| 239 | 239 | ||
| 240 | - bool cache_valid; | 240 | + bool cache_valid{false}; |
| 241 | std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations; | 241 | std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations; |
| 242 | std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field; | 242 | std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field; |
| 243 | std::map<QPDFObjGen, std::string> field_to_name; | 243 | std::map<QPDFObjGen, std::string> field_to_name; |
libqpdf/AES_PDF_native.cc
| @@ -17,8 +17,7 @@ AES_PDF_native::AES_PDF_native( | @@ -17,8 +17,7 @@ AES_PDF_native::AES_PDF_native( | ||
| 17 | unsigned char* cbc_block) : | 17 | unsigned char* cbc_block) : |
| 18 | encrypt(encrypt), | 18 | encrypt(encrypt), |
| 19 | cbc_mode(cbc_mode), | 19 | cbc_mode(cbc_mode), |
| 20 | - cbc_block(cbc_block), | ||
| 21 | - nrounds(0) | 20 | + cbc_block(cbc_block) |
| 22 | { | 21 | { |
| 23 | size_t keybits = 8 * key_bytes; | 22 | size_t keybits = 8 * key_bytes; |
| 24 | this->key = std::make_unique<unsigned char[]>(key_bytes); | 23 | this->key = std::make_unique<unsigned char[]>(key_bytes); |
libqpdf/BitWriter.cc
libqpdf/ClosedFileInputSource.cc
| @@ -3,9 +3,7 @@ | @@ -3,9 +3,7 @@ | ||
| 3 | #include <qpdf/FileInputSource.hh> | 3 | #include <qpdf/FileInputSource.hh> |
| 4 | 4 | ||
| 5 | ClosedFileInputSource::ClosedFileInputSource(char const* filename) : | 5 | ClosedFileInputSource::ClosedFileInputSource(char const* filename) : |
| 6 | - filename(filename), | ||
| 7 | - offset(0), | ||
| 8 | - stay_open(false) | 6 | + filename(filename) |
| 9 | { | 7 | { |
| 10 | } | 8 | } |
| 11 | 9 |
libqpdf/ContentNormalizer.cc
| @@ -5,12 +5,6 @@ | @@ -5,12 +5,6 @@ | ||
| 5 | 5 | ||
| 6 | using namespace qpdf; | 6 | using namespace qpdf; |
| 7 | 7 | ||
| 8 | -ContentNormalizer::ContentNormalizer() : | ||
| 9 | - any_bad_tokens(false), | ||
| 10 | - last_token_was_bad(false) | ||
| 11 | -{ | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | void | 8 | void |
| 15 | ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) | 9 | ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) |
| 16 | { | 10 | { |
libqpdf/InsecureRandomDataProvider.cc
| @@ -4,11 +4,6 @@ | @@ -4,11 +4,6 @@ | ||
| 4 | #include <qpdf/qpdf-config.h> | 4 | #include <qpdf/qpdf-config.h> |
| 5 | #include <cstdlib> | 5 | #include <cstdlib> |
| 6 | 6 | ||
| 7 | -InsecureRandomDataProvider::InsecureRandomDataProvider() : | ||
| 8 | - seeded_random(false) | ||
| 9 | -{ | ||
| 10 | -} | ||
| 11 | - | ||
| 12 | void | 7 | void |
| 13 | InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) | 8 | InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) |
| 14 | { | 9 | { |
libqpdf/NNTree.cc
| @@ -28,8 +28,7 @@ error(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) | @@ -28,8 +28,7 @@ error(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) : | 30 | NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) : |
| 31 | - impl(impl), | ||
| 32 | - item_number(-1) | 31 | + impl(impl) |
| 33 | { | 32 | { |
| 34 | } | 33 | } |
| 35 | 34 | ||
| @@ -666,7 +665,6 @@ NNTreeImpl::NNTreeImpl( | @@ -666,7 +665,6 @@ NNTreeImpl::NNTreeImpl( | ||
| 666 | NNTreeDetails const& details, QPDF& qpdf, QPDFObjectHandle& oh, bool auto_repair) : | 665 | NNTreeDetails const& details, QPDF& qpdf, QPDFObjectHandle& oh, bool auto_repair) : |
| 667 | details(details), | 666 | details(details), |
| 668 | qpdf(qpdf), | 667 | qpdf(qpdf), |
| 669 | - split_threshold(32), | ||
| 670 | oh(oh), | 668 | oh(oh), |
| 671 | auto_repair(auto_repair) | 669 | auto_repair(auto_repair) |
| 672 | { | 670 | { |
libqpdf/Pl_SHA2.cc
| @@ -5,8 +5,7 @@ | @@ -5,8 +5,7 @@ | ||
| 5 | #include <stdexcept> | 5 | #include <stdexcept> |
| 6 | 6 | ||
| 7 | Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : | 7 | Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : |
| 8 | - Pipeline("sha2", next), | ||
| 9 | - in_progress(false) | 8 | + Pipeline("sha2", next) |
| 10 | { | 9 | { |
| 11 | if (bits) { | 10 | if (bits) { |
| 12 | resetBits(bits); | 11 | resetBits(bits); |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -9,11 +9,6 @@ | @@ -9,11 +9,6 @@ | ||
| 9 | 9 | ||
| 10 | using namespace qpdf; | 10 | using namespace qpdf; |
| 11 | 11 | ||
| 12 | -QPDFAcroFormDocumentHelper::Members::Members() : | ||
| 13 | - cache_valid(false) | ||
| 14 | -{ | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : | 12 | QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : |
| 18 | QPDFDocumentHelper(qpdf), | 13 | QPDFDocumentHelper(qpdf), |
| 19 | m(new Members()) | 14 | m(new Members()) |
libqpdf/QPDFArgParser.cc
| @@ -18,12 +18,7 @@ QPDFArgParser::Members::Members(int argc, char const* const argv[], char const* | @@ -18,12 +18,7 @@ QPDFArgParser::Members::Members(int argc, char const* const argv[], char const* | ||
| 18 | 18 | ||
| 19 | argc(argc), | 19 | argc(argc), |
| 20 | argv(argv), | 20 | argv(argv), |
| 21 | - progname_env(progname_env), | ||
| 22 | - cur_arg(0), | ||
| 23 | - bash_completion(false), | ||
| 24 | - zsh_completion(false), | ||
| 25 | - option_table(nullptr), | ||
| 26 | - final_check_handler(nullptr) | 21 | + progname_env(progname_env) |
| 27 | { | 22 | { |
| 28 | auto tmp = QUtil::make_unique_cstr(argv[0]); | 23 | auto tmp = QUtil::make_unique_cstr(argv[0]); |
| 29 | whoami = QUtil::getWhoami(tmp.get()); | 24 | whoami = QUtil::getWhoami(tmp.get()); |
libqpdf/ResourceFinder.cc
| 1 | #include <qpdf/ResourceFinder.hh> | 1 | #include <qpdf/ResourceFinder.hh> |
| 2 | 2 | ||
| 3 | -ResourceFinder::ResourceFinder() : | ||
| 4 | - last_name_offset(0) | ||
| 5 | -{ | ||
| 6 | -} | ||
| 7 | - | ||
| 8 | void | 3 | void |
| 9 | ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t) | 4 | ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t) |
| 10 | { | 5 | { |
libqpdf/qpdf/AES_PDF_native.hh
| @@ -25,7 +25,7 @@ class AES_PDF_native | @@ -25,7 +25,7 @@ class AES_PDF_native | ||
| 25 | unsigned char* cbc_block; | 25 | unsigned char* cbc_block; |
| 26 | std::unique_ptr<unsigned char[]> key; | 26 | std::unique_ptr<unsigned char[]> key; |
| 27 | std::unique_ptr<uint32_t[]> rk; | 27 | std::unique_ptr<uint32_t[]> rk; |
| 28 | - unsigned int nrounds; | 28 | + unsigned int nrounds{0}; |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | #endif // AES_PDF_NATIVE_HH | 31 | #endif // AES_PDF_NATIVE_HH |
libqpdf/qpdf/BitWriter.hh
| @@ -21,8 +21,8 @@ class BitWriter | @@ -21,8 +21,8 @@ class BitWriter | ||
| 21 | 21 | ||
| 22 | private: | 22 | private: |
| 23 | Pipeline* pl; | 23 | Pipeline* pl; |
| 24 | - unsigned char ch; | ||
| 25 | - size_t bit_offset; | 24 | + unsigned char ch{0}; |
| 25 | + size_t bit_offset{7}; | ||
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | #endif // BITWRITER_HH | 28 | #endif // BITWRITER_HH |
libqpdf/qpdf/ContentNormalizer.hh
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | class ContentNormalizer final: public QPDFObjectHandle::TokenFilter | 6 | class ContentNormalizer final: public QPDFObjectHandle::TokenFilter |
| 7 | { | 7 | { |
| 8 | public: | 8 | public: |
| 9 | - ContentNormalizer(); | 9 | + ContentNormalizer() = default; |
| 10 | ~ContentNormalizer() final = default; | 10 | ~ContentNormalizer() final = default; |
| 11 | void handleToken(QPDFTokenizer::Token const&) final; | 11 | void handleToken(QPDFTokenizer::Token const&) final; |
| 12 | 12 | ||
| @@ -22,8 +22,8 @@ class ContentNormalizer final: public QPDFObjectHandle::TokenFilter | @@ -22,8 +22,8 @@ class ContentNormalizer final: public QPDFObjectHandle::TokenFilter | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | private: | 24 | private: |
| 25 | - bool any_bad_tokens; | ||
| 26 | - bool last_token_was_bad; | 25 | + bool any_bad_tokens{false}; |
| 26 | + bool last_token_was_bad{false}; | ||
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | #endif // CONTENTNORMALIZER_HH | 29 | #endif // CONTENTNORMALIZER_HH |
libqpdf/qpdf/InsecureRandomDataProvider.hh
| @@ -3,18 +3,18 @@ | @@ -3,18 +3,18 @@ | ||
| 3 | 3 | ||
| 4 | #include <qpdf/RandomDataProvider.hh> | 4 | #include <qpdf/RandomDataProvider.hh> |
| 5 | 5 | ||
| 6 | -class InsecureRandomDataProvider: public RandomDataProvider | 6 | +class InsecureRandomDataProvider final: public RandomDataProvider |
| 7 | { | 7 | { |
| 8 | public: | 8 | public: |
| 9 | - InsecureRandomDataProvider(); | ||
| 10 | - ~InsecureRandomDataProvider() override = default; | ||
| 11 | - void provideRandomData(unsigned char* data, size_t len) override; | 9 | + InsecureRandomDataProvider() = default; |
| 10 | + ~InsecureRandomDataProvider() final = default; | ||
| 11 | + void provideRandomData(unsigned char* data, size_t len) final; | ||
| 12 | static RandomDataProvider* getInstance(); | 12 | static RandomDataProvider* getInstance(); |
| 13 | 13 | ||
| 14 | private: | 14 | private: |
| 15 | long random(); | 15 | long random(); |
| 16 | 16 | ||
| 17 | - bool seeded_random; | 17 | + bool seeded_random{false}; |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | #endif // INSECURERANDOMDATAPROVIDER_HH | 20 | #endif // INSECURERANDOMDATAPROVIDER_HH |
libqpdf/qpdf/NNTree.hh
| @@ -84,7 +84,7 @@ class NNTreeIterator | @@ -84,7 +84,7 @@ class NNTreeIterator | ||
| 84 | NNTreeImpl& impl; | 84 | NNTreeImpl& impl; |
| 85 | std::list<PathElement> path; | 85 | std::list<PathElement> path; |
| 86 | QPDFObjectHandle node; | 86 | QPDFObjectHandle node; |
| 87 | - int item_number; | 87 | + int item_number{-1}; |
| 88 | value_type ivalue; | 88 | value_type ivalue; |
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| @@ -123,7 +123,7 @@ class NNTreeImpl | @@ -123,7 +123,7 @@ class NNTreeImpl | ||
| 123 | 123 | ||
| 124 | NNTreeDetails const& details; | 124 | NNTreeDetails const& details; |
| 125 | QPDF& qpdf; | 125 | QPDF& qpdf; |
| 126 | - int split_threshold; | 126 | + int split_threshold{32}; |
| 127 | QPDFObjectHandle oh; | 127 | QPDFObjectHandle oh; |
| 128 | bool auto_repair; | 128 | bool auto_repair; |
| 129 | }; | 129 | }; |
libqpdf/qpdf/Pl_SHA2.hh
| @@ -25,7 +25,7 @@ class Pl_SHA2 final: public Pipeline | @@ -25,7 +25,7 @@ class Pl_SHA2 final: public Pipeline | ||
| 25 | std::string getRawDigest(); | 25 | std::string getRawDigest(); |
| 26 | 26 | ||
| 27 | private: | 27 | private: |
| 28 | - bool in_progress; | 28 | + bool in_progress{false}; |
| 29 | std::shared_ptr<QPDFCryptoImpl> crypto; | 29 | std::shared_ptr<QPDFCryptoImpl> crypto; |
| 30 | }; | 30 | }; |
| 31 | 31 |
libqpdf/qpdf/QPDFArgParser.hh
| @@ -206,9 +206,9 @@ class QPDFArgParser | @@ -206,9 +206,9 @@ class QPDFArgParser | ||
| 206 | char const* const* argv; | 206 | char const* const* argv; |
| 207 | std::string whoami; | 207 | std::string whoami; |
| 208 | std::string progname_env; | 208 | std::string progname_env; |
| 209 | - int cur_arg; | ||
| 210 | - bool bash_completion; | ||
| 211 | - bool zsh_completion; | 209 | + int cur_arg{0}; |
| 210 | + bool bash_completion{false}; | ||
| 211 | + bool zsh_completion{false}; | ||
| 212 | std::string bash_prev; | 212 | std::string bash_prev; |
| 213 | std::string bash_cur; | 213 | std::string bash_cur; |
| 214 | std::string bash_line; | 214 | std::string bash_line; |
| @@ -216,9 +216,9 @@ class QPDFArgParser | @@ -216,9 +216,9 @@ class QPDFArgParser | ||
| 216 | std::map<std::string, option_table_t> option_tables; | 216 | std::map<std::string, option_table_t> option_tables; |
| 217 | option_table_t main_option_table; | 217 | option_table_t main_option_table; |
| 218 | option_table_t help_option_table; | 218 | option_table_t help_option_table; |
| 219 | - option_table_t* option_table; | 219 | + option_table_t* option_table{nullptr}; |
| 220 | std::string option_table_name; | 220 | std::string option_table_name; |
| 221 | - bare_arg_handler_t final_check_handler; | 221 | + bare_arg_handler_t final_check_handler{nullptr}; |
| 222 | std::vector<std::string> new_argv; | 222 | std::vector<std::string> new_argv; |
| 223 | std::vector<std::string> bash_argv; | 223 | std::vector<std::string> bash_argv; |
| 224 | std::vector<char const*> argv_ph; | 224 | std::vector<char const*> argv_ph; |
libqpdf/qpdf/QPDFCrypto_native.hh
| @@ -8,37 +8,37 @@ | @@ -8,37 +8,37 @@ | ||
| 8 | #include <qpdf/SHA2_native.hh> | 8 | #include <qpdf/SHA2_native.hh> |
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | 10 | ||
| 11 | -class QPDFCrypto_native: public QPDFCryptoImpl | 11 | +class QPDFCrypto_native final: public QPDFCryptoImpl |
| 12 | { | 12 | { |
| 13 | public: | 13 | public: |
| 14 | QPDFCrypto_native() = default; | 14 | QPDFCrypto_native() = default; |
| 15 | 15 | ||
| 16 | - virtual ~QPDFCrypto_native() = default; | 16 | + ~QPDFCrypto_native() final = default; |
| 17 | 17 | ||
| 18 | - virtual void provideRandomData(unsigned char* data, size_t len); | 18 | + void provideRandomData(unsigned char* data, size_t len) final; |
| 19 | 19 | ||
| 20 | - virtual void MD5_init(); | ||
| 21 | - virtual void MD5_update(unsigned char const* data, size_t len); | ||
| 22 | - virtual void MD5_finalize(); | ||
| 23 | - virtual void MD5_digest(MD5_Digest); | 20 | + void MD5_init() final; |
| 21 | + void MD5_update(unsigned char const* data, size_t len) final; | ||
| 22 | + void MD5_finalize() final; | ||
| 23 | + void MD5_digest(MD5_Digest) final; | ||
| 24 | 24 | ||
| 25 | - virtual void RC4_init(unsigned char const* key_data, int key_len = -1); | ||
| 26 | - virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0); | ||
| 27 | - virtual void RC4_finalize(); | 25 | + void RC4_init(unsigned char const* key_data, int key_len = -1) final; |
| 26 | + void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0) final; | ||
| 27 | + void RC4_finalize() final; | ||
| 28 | 28 | ||
| 29 | - virtual void SHA2_init(int bits); | ||
| 30 | - virtual void SHA2_update(unsigned char const* data, size_t len); | ||
| 31 | - virtual void SHA2_finalize(); | ||
| 32 | - virtual std::string SHA2_digest(); | 29 | + void SHA2_init(int bits) final; |
| 30 | + void SHA2_update(unsigned char const* data, size_t len) final; | ||
| 31 | + void SHA2_finalize() final; | ||
| 32 | + std::string SHA2_digest() final; | ||
| 33 | 33 | ||
| 34 | - virtual void rijndael_init( | 34 | + void rijndael_init( |
| 35 | bool encrypt, | 35 | bool encrypt, |
| 36 | unsigned char const* key_data, | 36 | unsigned char const* key_data, |
| 37 | size_t key_len, | 37 | size_t key_len, |
| 38 | bool cbc_mode, | 38 | bool cbc_mode, |
| 39 | - unsigned char* cbc_block); | ||
| 40 | - virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data); | ||
| 41 | - virtual void rijndael_finalize(); | 39 | + unsigned char* cbc_block) final; |
| 40 | + void rijndael_process(unsigned char* in_data, unsigned char* out_data) final; | ||
| 41 | + void rijndael_finalize() final; | ||
| 42 | 42 | ||
| 43 | private: | 43 | private: |
| 44 | std::shared_ptr<MD5_native> md5; | 44 | std::shared_ptr<MD5_native> md5; |
libqpdf/qpdf/ResourceFinder.hh
| @@ -3,20 +3,20 @@ | @@ -3,20 +3,20 @@ | ||
| 3 | 3 | ||
| 4 | #include <qpdf/QPDFObjectHandle.hh> | 4 | #include <qpdf/QPDFObjectHandle.hh> |
| 5 | 5 | ||
| 6 | -class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | 6 | +class ResourceFinder final: public QPDFObjectHandle::ParserCallbacks |
| 7 | { | 7 | { |
| 8 | public: | 8 | public: |
| 9 | - ResourceFinder(); | ||
| 10 | - ~ResourceFinder() override = default; | ||
| 11 | - void handleObject(QPDFObjectHandle, size_t, size_t) override; | ||
| 12 | - void handleEOF() override; | 9 | + ResourceFinder() = default; |
| 10 | + ~ResourceFinder() final = default; | ||
| 11 | + void handleObject(QPDFObjectHandle, size_t, size_t) final; | ||
| 12 | + void handleEOF() final; | ||
| 13 | std::set<std::string> const& getNames() const; | 13 | std::set<std::string> const& getNames() const; |
| 14 | std::map<std::string, std::map<std::string, std::set<size_t>>> const& | 14 | std::map<std::string, std::map<std::string, std::set<size_t>>> const& |
| 15 | getNamesByResourceType() const; | 15 | getNamesByResourceType() const; |
| 16 | 16 | ||
| 17 | private: | 17 | private: |
| 18 | std::string last_name; | 18 | std::string last_name; |
| 19 | - size_t last_name_offset; | 19 | + size_t last_name_offset{0}; |
| 20 | std::set<std::string> names; | 20 | std::set<std::string> names; |
| 21 | std::map<std::string, std::map<std::string, std::set<size_t>>> names_by_resource_type; | 21 | std::map<std::string, std::map<std::string, std::set<size_t>>> names_by_resource_type; |
| 22 | }; | 22 | }; |