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
{
public:
StringCounter() :
count(0)
StringCounter()
{
}
~StringCounter() override = default;
@ -36,7 +35,7 @@ class StringCounter: public QPDFObjectHandle::TokenFilter
int getCount() const;
private:
int count;
int count{0};
};
void

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -59,7 +59,7 @@ namespace
std::list<std::shared_ptr<JSONHandler>> json_handlers;
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::CopyAttConfig> c_copy_att;
std::shared_ptr<QPDFJob::AttConfig> c_att;
@ -71,7 +71,6 @@ namespace
Handlers::Handlers(bool partial, std::shared_ptr<QPDFJob::Config> c_main) :
partial(partial),
jh(nullptr),
c_main(c_main)
{
initHandlers();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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