2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Code tidy - Clang-Tidy rule modernize-use-default-member-init

This commit is contained in:
m-holger 2023-06-01 14:12:39 +01:00
parent 7bc0f1d828
commit 5906dd5c1f
21 changed files with 131 additions and 232 deletions

View File

@ -26,8 +26,7 @@ usage()
class StringCounter: public QPDFObjectHandle::TokenFilter class StringCounter: public QPDFObjectHandle::TokenFilter
{ {
public: public:
StringCounter() : StringCounter()
count(0)
{ {
} }
~StringCounter() override = default; ~StringCounter() override = default;
@ -36,7 +35,7 @@ class StringCounter: public QPDFObjectHandle::TokenFilter
int getCount() const; int getCount() const;
private: private:
int count; int count{0};
}; };
void void

View File

@ -31,22 +31,18 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
size_t getHeight() const; size_t getHeight() const;
private: private:
size_t width; size_t width{400};
size_t stripe_height; size_t stripe_height{80};
std::string color_space; std::string color_space;
std::string filter; std::string filter;
size_t n_stripes; size_t n_stripes{6};
std::vector<std::string> stripes; std::vector<std::string> stripes;
J_COLOR_SPACE j_color_space; J_COLOR_SPACE j_color_space{JCS_UNKNOWN};
}; };
ImageProvider::ImageProvider(std::string const& color_space, std::string const& filter) : ImageProvider::ImageProvider(std::string const& color_space, std::string const& filter) :
width(400),
stripe_height(80),
color_space(color_space), color_space(color_space),
filter(filter), filter(filter)
n_stripes(6),
j_color_space(JCS_UNKNOWN)
{ {
if (color_space == "/DeviceCMYK") { if (color_space == "/DeviceCMYK") {
j_color_space = JCS_CMYK; j_color_space = JCS_CMYK;

View File

@ -33,8 +33,7 @@ class QPDF_DLL_CLASS InputSource
{ {
public: public:
QPDF_DLL QPDF_DLL
InputSource() : InputSource()
last_offset(0)
{ {
} }
QPDF_DLL QPDF_DLL
@ -86,7 +85,7 @@ class QPDF_DLL_CLASS InputSource
inline void loadBuffer(); inline void loadBuffer();
protected: protected:
qpdf_offset_t last_offset; qpdf_offset_t last_offset{0};
private: private:
class QPDF_DLL_PRIVATE Members class QPDF_DLL_PRIVATE Members

View File

@ -1150,58 +1150,40 @@ class QPDF
// PDF 1.4: Table F.4 // PDF 1.4: Table F.4
struct HPageOffsetEntry struct HPageOffsetEntry
{ {
HPageOffsetEntry() : HPageOffsetEntry()
delta_nobjects(0),
delta_page_length(0),
nshared_objects(0),
delta_content_offset(0),
delta_content_length(0)
{ {
} }
int delta_nobjects; // 1 int delta_nobjects{0}; // 1
qpdf_offset_t delta_page_length; // 2 qpdf_offset_t delta_page_length{0}; // 2
int nshared_objects; // 3
// vectors' sizes = nshared_objects // vectors' sizes = nshared_objects
std::vector<int> shared_identifiers; // 4 int nshared_objects{0}; // 3
std::vector<int> shared_numerators; // 5 std::vector<int> shared_identifiers; // 4
qpdf_offset_t delta_content_offset; // 6 std::vector<int> shared_numerators; // 5
qpdf_offset_t delta_content_length; // 7 qpdf_offset_t delta_content_offset{0}; // 6
qpdf_offset_t delta_content_length{0}; // 7
}; };
// PDF 1.4: Table F.3 // PDF 1.4: Table F.3
struct HPageOffset struct HPageOffset
{ {
HPageOffset() : HPageOffset()
min_nobjects(0),
first_page_offset(0),
nbits_delta_nobjects(0),
min_page_length(0),
nbits_delta_page_length(0),
min_content_offset(0),
nbits_delta_content_offset(0),
min_content_length(0),
nbits_delta_content_length(0),
nbits_nshared_objects(0),
nbits_shared_identifier(0),
nbits_shared_numerator(0),
shared_denominator(0)
{ {
} }
int min_nobjects; // 1 int min_nobjects{0}; // 1
qpdf_offset_t first_page_offset; // 2 qpdf_offset_t first_page_offset{0}; // 2
int nbits_delta_nobjects; // 3 int nbits_delta_nobjects{0}; // 3
int min_page_length; // 4 int min_page_length{0}; // 4
int nbits_delta_page_length; // 5 int nbits_delta_page_length{0}; // 5
int min_content_offset; // 6 int min_content_offset{0}; // 6
int nbits_delta_content_offset; // 7 int nbits_delta_content_offset{0}; // 7
int min_content_length; // 8 int min_content_length{0}; // 8
int nbits_delta_content_length; // 9 int nbits_delta_content_length{0}; // 9
int nbits_nshared_objects; // 10 int nbits_nshared_objects{0}; // 10
int nbits_shared_identifier; // 11 int nbits_shared_identifier{0}; // 11
int nbits_shared_numerator; // 12 int nbits_shared_numerator{0}; // 12
int shared_denominator; // 13 int shared_denominator{0}; // 13
// vector size is npages // vector size is npages
std::vector<HPageOffsetEntry> entries; std::vector<HPageOffsetEntry> entries;
}; };
@ -1209,40 +1191,30 @@ class QPDF
// PDF 1.4: Table F.6 // PDF 1.4: Table F.6
struct HSharedObjectEntry struct HSharedObjectEntry
{ {
HSharedObjectEntry() : HSharedObjectEntry()
delta_group_length(0),
signature_present(0),
nobjects_minus_one(0)
{ {
} }
// Item 3 is a 128-bit signature (unsupported by Acrobat) // Item 3 is a 128-bit signature (unsupported by Acrobat)
int delta_group_length; // 1 int delta_group_length{0}; // 1
int signature_present; // 2 -- always 0 int signature_present{0}; // 2 -- always 0
int nobjects_minus_one; // 4 -- always 0 int nobjects_minus_one{0}; // 4 -- always 0
}; };
// PDF 1.4: Table F.5 // PDF 1.4: Table F.5
struct HSharedObject struct HSharedObject
{ {
HSharedObject() : HSharedObject()
first_shared_obj(0),
first_shared_offset(0),
nshared_first_page(0),
nshared_total(0),
nbits_nobjects(0),
min_group_length(0),
nbits_delta_group_length(0)
{ {
} }
int first_shared_obj; // 1 int first_shared_obj{0}; // 1
qpdf_offset_t first_shared_offset; // 2 qpdf_offset_t first_shared_offset{0}; // 2
int nshared_first_page; // 3 int nshared_first_page{0}; // 3
int nshared_total; // 4 int nshared_total{0}; // 4
int nbits_nobjects; // 5 int nbits_nobjects{0}; // 5
int min_group_length; // 6 int min_group_length{0}; // 6
int nbits_delta_group_length; // 7 int nbits_delta_group_length{0}; // 7
// vector size is nshared_total // vector size is nshared_total
std::vector<HSharedObjectEntry> entries; std::vector<HSharedObjectEntry> entries;
}; };
@ -1250,18 +1222,14 @@ class QPDF
// PDF 1.4: Table F.9 // PDF 1.4: Table F.9
struct HGeneric struct HGeneric
{ {
HGeneric() : HGeneric()
first_object(0),
first_object_offset(0),
nobjects(0),
group_length(0)
{ {
} }
int first_object; // 1 int first_object{0}; // 1
qpdf_offset_t first_object_offset; // 2 qpdf_offset_t first_object_offset{0}; // 2
int nobjects; // 3 int nobjects{0}; // 3
int group_length; // 4 int group_length{0}; // 4
}; };
// Other linearization data structures // Other linearization data structures
@ -1269,26 +1237,18 @@ class QPDF
// Initialized from Linearization Parameter dictionary // Initialized from Linearization Parameter dictionary
struct LinParameters struct LinParameters
{ {
LinParameters() : LinParameters()
file_size(0),
first_page_object(0),
first_page_end(0),
npages(0),
xref_zero_offset(0),
first_page(0),
H_offset(0),
H_length(0)
{ {
} }
qpdf_offset_t file_size; // /L qpdf_offset_t file_size{0}; // /L
int first_page_object; // /O int first_page_object{0}; // /O
qpdf_offset_t first_page_end; // /E qpdf_offset_t first_page_end{0}; // /E
int npages; // /N int npages{0}; // /N
qpdf_offset_t xref_zero_offset; // /T qpdf_offset_t xref_zero_offset{0}; // /T
int first_page; // /P int first_page{0}; // /P
qpdf_offset_t H_offset; // offset of primary hint stream qpdf_offset_t H_offset{0}; // offset of primary hint stream
qpdf_offset_t H_length; // length of primary hint stream qpdf_offset_t H_length{0}; // length of primary hint stream
}; };
// Computed hint table value data structures. These tables contain the computed values on which // Computed hint table value data structures. These tables contain the computed values on which
@ -1304,14 +1264,12 @@ class QPDF
struct CHPageOffsetEntry struct CHPageOffsetEntry
{ {
CHPageOffsetEntry() : CHPageOffsetEntry()
nobjects(0),
nshared_objects(0)
{ {
} }
int nobjects; int nobjects{0};
int nshared_objects; int nshared_objects{0};
// vectors' sizes = nshared_objects // vectors' sizes = nshared_objects
std::vector<int> shared_identifiers; std::vector<int> shared_identifiers;
}; };
@ -1335,16 +1293,13 @@ class QPDF
// PDF 1.4: Table F.5 // PDF 1.4: Table F.5
struct CHSharedObject struct CHSharedObject
{ {
CHSharedObject() : CHSharedObject()
first_shared_obj(0),
nshared_first_page(0),
nshared_total(0)
{ {
} }
int first_shared_obj; int first_shared_obj{0};
int nshared_first_page; int nshared_first_page{0};
int nshared_total; int nshared_total{0};
// vector size is nshared_total // vector size is nshared_total
std::vector<CHSharedObjectEntry> entries; std::vector<CHSharedObjectEntry> entries;
}; };

View File

@ -145,8 +145,7 @@ class QPDFJob
struct AddAttachment struct AddAttachment
{ {
AddAttachment() : AddAttachment()
replace(false)
{ {
} }
@ -157,7 +156,7 @@ class QPDFJob
std::string moddate; std::string moddate;
std::string mimetype; std::string mimetype;
std::string description; std::string description;
bool replace; bool replace{false};
}; };
struct PageSpec struct PageSpec

View File

@ -34,9 +34,7 @@ class QPDFObjGen
public: public:
// ABI: change to default. // ABI: change to default.
QPDF_DLL QPDF_DLL
QPDFObjGen() : QPDFObjGen()
obj(0),
gen(0)
{ {
} }
QPDF_DLL QPDF_DLL

View File

@ -588,14 +588,7 @@ namespace
JSONParser(InputSource& is, JSON::Reactor* reactor) : JSONParser(InputSource& is, JSON::Reactor* reactor) :
is(is), is(is),
reactor(reactor), reactor(reactor),
lex_state(ls_top), p(buf)
bytes(0),
p(buf),
u_count(0),
offset(0),
done(false),
parser_state(ps_top),
dict_key_offset(0)
{ {
} }
@ -665,20 +658,20 @@ namespace
InputSource& is; InputSource& is;
JSON::Reactor* reactor; JSON::Reactor* reactor;
lex_state_e lex_state; lex_state_e lex_state{ls_top};
char buf[16384]; char buf[16384];
size_t bytes; size_t bytes{0};
char const* p; char const* p;
qpdf_offset_t u_count; qpdf_offset_t u_count{0};
unsigned long u_value{0}; unsigned long u_value{0};
qpdf_offset_t offset; qpdf_offset_t offset{0};
bool done; bool done{false};
std::string token; std::string token;
qpdf_offset_t token_start{0}; qpdf_offset_t token_start{0};
parser_state_e parser_state; parser_state_e parser_state{ps_top};
std::vector<StackFrame> stack; std::vector<StackFrame> stack;
std::string dict_key; std::string dict_key;
qpdf_offset_t dict_key_offset; qpdf_offset_t dict_key_offset{0};
}; };
} // namespace } // namespace

View File

@ -473,15 +473,14 @@ namespace
virtual void handleToken(QPDFTokenizer::Token const&) override; virtual void handleToken(QPDFTokenizer::Token const&) override;
private: private:
size_t offset; size_t offset{0};
std::map<std::string, std::map<size_t, std::string>> to_replace; std::map<std::string, std::map<size_t, std::string>> to_replace;
}; };
} // namespace } // namespace
ResourceReplacer::ResourceReplacer( ResourceReplacer::ResourceReplacer(
std::map<std::string, std::map<std::string, std::string>> const& dr_map, std::map<std::string, std::map<std::string, std::string>> const& dr_map,
std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames) : std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames)
offset(0)
{ {
// We have: // We have:
// * dr_map[resource_type][key] == new_key // * dr_map[resource_type][key] == new_key

View File

@ -481,8 +481,8 @@ namespace
std::vector<std::string> opt; std::vector<std::string> opt;
double tf; double tf;
QPDFObjectHandle::Rectangle bbox; QPDFObjectHandle::Rectangle bbox;
enum { st_top, st_bmc, st_emc, st_end } state; enum { st_top, st_bmc, st_emc, st_end } state{st_top};
bool replaced; bool replaced{false};
}; };
} // namespace } // namespace
@ -496,9 +496,7 @@ ValueSetter::ValueSetter(
V(V), V(V),
opt(opt), opt(opt),
tf(tf), tf(tf),
bbox(bbox), bbox(bbox)
state(st_top),
replaced(false)
{ {
} }
@ -659,21 +657,17 @@ namespace
std::string getDA(); std::string getDA();
private: private:
double tf; double tf{11.0};
int tf_idx; int tf_idx{-1};
std::string font_name; std::string font_name;
double last_num; double last_num{0.0};
int last_num_idx; int last_num_idx{-1};
std::string last_name; std::string last_name;
std::vector<std::string> DA; std::vector<std::string> DA;
}; };
} // namespace } // namespace
TfFinder::TfFinder() : TfFinder::TfFinder()
tf(11.0),
tf_idx(-1),
last_num(0.0),
last_num_idx(-1)
{ {
} }

View File

@ -40,18 +40,15 @@ namespace
std::shared_ptr<QPDFJob::UOConfig> c_uo; std::shared_ptr<QPDFJob::UOConfig> c_uo;
std::shared_ptr<QPDFJob::EncConfig> c_enc; std::shared_ptr<QPDFJob::EncConfig> c_enc;
std::vector<std::string> accumulated_args; std::vector<std::string> accumulated_args;
std::shared_ptr<char> pages_password; std::shared_ptr<char> pages_password{nullptr};
bool gave_input; bool gave_input{false};
bool gave_output; bool gave_output{false};
}; };
} // namespace } // namespace
ArgParser::ArgParser(QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) : ArgParser::ArgParser(QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) :
ap(ap), ap(ap),
c_main(c_main), c_main(c_main)
pages_password(nullptr),
gave_input(false),
gave_output(false)
{ {
initOptionTables(); initOptionTables();
} }

View File

@ -59,7 +59,7 @@ namespace
std::list<std::shared_ptr<JSONHandler>> json_handlers; std::list<std::shared_ptr<JSONHandler>> json_handlers;
bool partial; bool partial;
JSONHandler* jh; // points to last of json_handlers JSONHandler* jh{nullptr}; // points to last of json_handlers
std::shared_ptr<QPDFJob::Config> c_main; std::shared_ptr<QPDFJob::Config> c_main;
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att; std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
std::shared_ptr<QPDFJob::AttConfig> c_att; std::shared_ptr<QPDFJob::AttConfig> c_att;
@ -71,7 +71,6 @@ namespace
Handlers::Handlers(bool partial, std::shared_ptr<QPDFJob::Config> c_main) : Handlers::Handlers(bool partial, std::shared_ptr<QPDFJob::Config> c_main) :
partial(partial), partial(partial),
jh(nullptr),
c_main(c_main) c_main(c_main)
{ {
initHandlers(); initHandlers();

View File

@ -12,8 +12,7 @@ namespace
{ {
public: public:
Pl_Track(char const* identifier, Pipeline* next) : Pl_Track(char const* identifier, Pipeline* next) :
Pipeline(identifier, next), Pipeline(identifier, next)
used(false)
{ {
} }
@ -37,7 +36,7 @@ namespace
} }
private: private:
bool used; bool used{false};
}; };
}; // namespace }; // namespace

View File

@ -189,13 +189,12 @@ namespace
unsigned char getLastChar(); unsigned char getLastChar();
private: private:
unsigned char last_char; unsigned char last_char{0};
}; };
} // namespace } // namespace
LastChar::LastChar(Pipeline* next) : LastChar::LastChar(Pipeline* next) :
Pipeline("lastchar", next), Pipeline("lastchar", next)
last_char(0)
{ {
} }

View File

@ -53,19 +53,16 @@ namespace
QPDFObjectHandle resources; QPDFObjectHandle resources;
std::string dict_str; std::string dict_str;
std::string bi_str; std::string bi_str;
int min_suffix; int min_suffix{1};
bool any_images; bool any_images{false};
enum { st_top, st_bi } state; enum { st_top, st_bi } state{st_top};
}; };
} // namespace } // namespace
InlineImageTracker::InlineImageTracker(QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) : InlineImageTracker::InlineImageTracker(QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) :
qpdf(qpdf), qpdf(qpdf),
min_size(min_size), min_size(min_size),
resources(resources), resources(resources)
min_suffix(1),
any_images(false),
state(st_top)
{ {
} }

View File

@ -1082,13 +1082,12 @@ namespace
private: private:
RandomDataProvider* default_provider; RandomDataProvider* default_provider;
RandomDataProvider* current_provider; RandomDataProvider* current_provider{nullptr};
}; };
} // namespace } // namespace
RandomDataProviderProvider::RandomDataProviderProvider() : RandomDataProviderProvider::RandomDataProviderProvider() :
default_provider(CryptoRandomDataProvider::getInstance()), default_provider(CryptoRandomDataProvider::getInstance())
current_provider(nullptr)
{ {
this->current_provider = default_provider; this->current_provider = default_provider;
} }

View File

@ -145,19 +145,15 @@ class QPDFArgParser
private: private:
struct OptionEntry struct OptionEntry
{ {
OptionEntry() : OptionEntry()
parameter_needed(false),
bare_arg_handler(nullptr),
param_arg_handler(nullptr),
invalid_choice_handler(nullptr)
{ {
} }
bool parameter_needed; bool parameter_needed{false};
std::string parameter_name; std::string parameter_name;
std::set<std::string> choices; std::set<std::string> choices;
bare_arg_handler_t bare_arg_handler; bare_arg_handler_t bare_arg_handler{nullptr};
param_arg_handler_t param_arg_handler; param_arg_handler_t param_arg_handler{nullptr};
param_arg_handler_t invalid_choice_handler; param_arg_handler_t invalid_choice_handler{nullptr};
}; };
typedef std::map<std::string, OptionEntry> option_table_t; typedef std::map<std::string, OptionEntry> option_table_t;

View File

@ -28,12 +28,11 @@ class ArgParser
void output(std::string const&); void output(std::string const&);
QPDFArgParser ap; QPDFArgParser ap;
int quacks; int quacks{0};
}; };
ArgParser::ArgParser(int argc, char* argv[]) : ArgParser::ArgParser(int argc, char* argv[]) :
ap(QPDFArgParser(argc, argv, "TEST_ARG_PARSER")), ap(QPDFArgParser(argc, argv, "TEST_ARG_PARSER"))
quacks(0)
{ {
initOptions(); initOptions();
} }

View File

@ -10,21 +10,19 @@
static void static void
usage() usage()
{ {
std::cerr << "Usage: dct_compress infile outfile width height" std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << std::endl;
<< " {rgb|cmyk|gray}" << std::endl;
exit(2); exit(2);
} }
class Callback: public Pl_DCT::CompressConfig class Callback: public Pl_DCT::CompressConfig
{ {
public: public:
Callback() : Callback()
called(false)
{ {
} }
~Callback() override = default; ~Callback() override = default;
void apply(jpeg_compress_struct*) override; void apply(jpeg_compress_struct*) override;
bool called; bool called{false};
}; };
void void

View File

@ -46,42 +46,29 @@ class QdfFixer
st_before_trailer, st_before_trailer,
st_in_trailer, st_in_trailer,
st_done, st_done,
} state; } state{st_top};
size_t lineno; size_t lineno{0};
qpdf_offset_t offset; qpdf_offset_t offset{0};
qpdf_offset_t last_offset; qpdf_offset_t last_offset{0};
int last_obj; int last_obj{0};
std::vector<QPDFXRefEntry> xref; std::vector<QPDFXRefEntry> xref;
qpdf_offset_t stream_start; qpdf_offset_t stream_start{0};
size_t stream_length; size_t stream_length{0};
qpdf_offset_t xref_offset; qpdf_offset_t xref_offset{0};
size_t xref_f1_nbytes; size_t xref_f1_nbytes{0};
size_t xref_f2_nbytes; size_t xref_f2_nbytes{0};
size_t xref_size; size_t xref_size{0};
std::vector<std::string_view> ostream; std::vector<std::string_view> ostream;
std::vector<qpdf_offset_t> ostream_offsets; std::vector<qpdf_offset_t> ostream_offsets;
std::vector<std::string_view> ostream_discarded; std::vector<std::string_view> ostream_discarded;
size_t ostream_idx; size_t ostream_idx{0};
int ostream_id; int ostream_id{0};
std::string ostream_extends; std::string ostream_extends;
}; };
QdfFixer::QdfFixer(std::string const& filename) : QdfFixer::QdfFixer(std::string const& filename) :
filename(filename), filename(filename)
state(st_top),
lineno(0),
offset(0),
last_offset(0),
last_obj(0),
stream_start(0),
stream_length(0),
xref_offset(0),
xref_f1_nbytes(0),
xref_f2_nbytes(0),
xref_size(0),
ostream_idx(0),
ostream_id(0)
{ {
} }

View File

@ -68,16 +68,15 @@ class Provider: public QPDFObjectHandle::StreamDataProvider
{ {
public: public:
Provider(std::shared_ptr<Buffer> b) : Provider(std::shared_ptr<Buffer> b) :
b(b), b(b)
bad_length(false)
{ {
} }
virtual ~Provider() = default; virtual ~Provider() = default;
virtual void virtual void
provideStreamData(int objid, int generation, Pipeline* p) provideStreamData(int objid, int generation, Pipeline* p)
{ {
// Don't change signature to use QPDFObjGen const& to detect // Don't change signature to use QPDFObjGen const& to detect problems forwarding to legacy
// problems forwarding to legacy implementations. // implementations.
p->write(b->getBuffer(), b->getSize()); p->write(b->getBuffer(), b->getSize());
if (this->bad_length) { if (this->bad_length) {
unsigned char ch = ' '; unsigned char ch = ' ';
@ -93,7 +92,7 @@ class Provider: public QPDFObjectHandle::StreamDataProvider
private: private:
std::shared_ptr<Buffer> b; std::shared_ptr<Buffer> b;
bool bad_length; bool bad_length{false};
}; };
class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks

View File

@ -67,15 +67,13 @@ class ImageChecker: public Pipeline
private: private:
size_t n; size_t n;
size_t offset; size_t offset{0};
bool okay; bool okay{true};
}; };
ImageChecker::ImageChecker(size_t n) : ImageChecker::ImageChecker(size_t n) :
Pipeline("image checker", nullptr), Pipeline("image checker", nullptr),
n(n), n(n)
offset(0),
okay(true)
{ {
} }