Initialize various class members in the headers. Then change ctors to "= default" when possible and also mark some members as const. Bug: pdfium:1669 Change-Id: I90b36f32567efb3dd663dde19ab3238f4a1fbb68 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79876 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index b74b08a..e259f01 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -47,18 +47,15 @@ private: bool Flush(); - FX_FILESIZE offset_; - size_t current_length_; + FX_FILESIZE offset_ = 0; + size_t current_length_ = 0; std::vector<uint8_t, FxAllocAllocator<uint8_t>> buffer_; RetainPtr<IFX_RetainableWriteStream> backing_file_; }; CFX_FileBufferArchive::CFX_FileBufferArchive( const RetainPtr<IFX_RetainableWriteStream>& file) - : offset_(0), - current_length_(0), - buffer_(kArchiveBufferSize), - backing_file_(file) { + : buffer_(kArchiveBufferSize), backing_file_(file) { DCHECK(file); }
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp index 8c3825d..185606b 100644 --- a/core/fpdfapi/page/cpdf_textobject.cpp +++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -15,7 +15,7 @@ #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) -CPDF_TextObjectItem::CPDF_TextObjectItem() : m_CharCode(0) {} +CPDF_TextObjectItem::CPDF_TextObjectItem() = default; CPDF_TextObjectItem::~CPDF_TextObjectItem() = default;
diff --git a/core/fpdfapi/page/cpdf_textobject.h b/core/fpdfapi/page/cpdf_textobject.h index cc8f64a..4735eea 100644 --- a/core/fpdfapi/page/cpdf_textobject.h +++ b/core/fpdfapi/page/cpdf_textobject.h
@@ -20,7 +20,7 @@ CPDF_TextObjectItem(); ~CPDF_TextObjectItem(); - uint32_t m_CharCode; + uint32_t m_CharCode = 0; CFX_PointF m_Origin; };
diff --git a/core/fpdfapi/parser/cpdf_flateencoder.cpp b/core/fpdfapi/parser/cpdf_flateencoder.cpp index 7d47c1a..d3440f2 100644 --- a/core/fpdfapi/parser/cpdf_flateencoder.cpp +++ b/core/fpdfapi/parser/cpdf_flateencoder.cpp
@@ -20,7 +20,7 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream, bool bFlateEncode) - : m_pAcc(pdfium::MakeRetain<CPDF_StreamAcc>(pStream)), m_dwSize(0) { + : m_pAcc(pdfium::MakeRetain<CPDF_StreamAcc>(pStream)) { m_pAcc->LoadAllDataRaw(); bool bHasFilter = pStream->HasFilter();
diff --git a/core/fpdfapi/parser/cpdf_flateencoder.h b/core/fpdfapi/parser/cpdf_flateencoder.h index 328fce7..4a86423 100644 --- a/core/fpdfapi/parser/cpdf_flateencoder.h +++ b/core/fpdfapi/parser/cpdf_flateencoder.h
@@ -34,7 +34,7 @@ private: RetainPtr<CPDF_StreamAcc> m_pAcc; - uint32_t m_dwSize; + uint32_t m_dwSize = 0; MaybeOwned<uint8_t, FxFreeDeleter> m_pData; // Only one of these two pointers is valid at any time.
diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp index f30753d..568c0bb 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.cpp
@@ -22,7 +22,7 @@ } // namespace CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() - : m_LastObjNum(0), m_pByteStringPool(std::make_unique<ByteStringPool>()) {} + : m_pByteStringPool(std::make_unique<ByteStringPool>()) {} CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { m_pByteStringPool.DeleteObject(); // Make weak.
diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h index 51aecec..1b1f861 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h
@@ -76,7 +76,7 @@ virtual RetainPtr<CPDF_Object> ParseIndirectObject(uint32_t objnum); private: - uint32_t m_LastObjNum; + uint32_t m_LastObjNum = 0; std::map<uint32_t, RetainPtr<CPDF_Object>> m_IndirectObjs; WeakPtr<ByteStringPool> m_pByteStringPool; };
diff --git a/core/fxcrt/cfx_bitstream.cpp b/core/fxcrt/cfx_bitstream.cpp index db0c852..7b1e502 100644 --- a/core/fxcrt/cfx_bitstream.cpp +++ b/core/fxcrt/cfx_bitstream.cpp
@@ -13,7 +13,7 @@ #include "third_party/base/check.h" CFX_BitStream::CFX_BitStream(pdfium::span<const uint8_t> pData) - : m_BitPos(0), m_BitSize(pData.size() * 8), m_pData(pData.data()) { + : m_BitSize(pData.size() * 8), m_pData(pData.data()) { DCHECK(pData.size() <= std::numeric_limits<uint32_t>::max() / 8); }
diff --git a/core/fxcrt/cfx_bitstream.h b/core/fxcrt/cfx_bitstream.h index baa2a9f..731a637 100644 --- a/core/fxcrt/cfx_bitstream.h +++ b/core/fxcrt/cfx_bitstream.h
@@ -31,9 +31,9 @@ } private: - uint32_t m_BitPos; - uint32_t m_BitSize; - UnownedPtr<const uint8_t> m_pData; + uint32_t m_BitPos = 0; + const uint32_t m_BitSize; + UnownedPtr<const uint8_t> const m_pData; }; #endif // CORE_FXCRT_CFX_BITSTREAM_H_
diff --git a/core/fxcrt/cfx_datetime.h b/core/fxcrt/cfx_datetime.h index b49c153..9fd6763 100644 --- a/core/fxcrt/cfx_datetime.h +++ b/core/fxcrt/cfx_datetime.h
@@ -16,14 +16,7 @@ public: static CFX_DateTime Now(); - CFX_DateTime() - : year_(0), - month_(0), - day_(0), - hour_(0), - minute_(0), - second_(0), - millisecond_(0) {} + CFX_DateTime() = default; CFX_DateTime(int32_t year, uint8_t month, uint8_t day, @@ -82,13 +75,13 @@ bool operator==(const CFX_DateTime& other) const; private: - int32_t year_; - uint8_t month_; - uint8_t day_; - uint8_t hour_; - uint8_t minute_; - uint8_t second_; - uint16_t millisecond_; + int32_t year_ = 0; + uint8_t month_ = 0; + uint8_t day_ = 0; + uint8_t hour_ = 0; + uint8_t minute_ = 0; + uint8_t second_ = 0; + uint16_t millisecond_ = 0; }; #endif // CORE_FXCRT_CFX_DATETIME_H_
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp index 76d5582..be1d1ec 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -17,7 +17,6 @@ #include <vector> #include "build/build_config.h" -#include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_memory_wrappers.h" #include "core/fxcrt/fx_safe_types.h" @@ -105,10 +104,7 @@ CFX_SeekableStreamProxy::CFX_SeekableStreamProxy( const RetainPtr<IFX_SeekableReadStream>& stream) - : m_wCodePage(FX_CODEPAGE_DefANSI), - m_wBOMLength(0), - m_iPosition(0), - m_pStream(stream) { + : m_pStream(stream) { DCHECK(m_pStream); Seek(From::Begin, 0);
diff --git a/core/fxcrt/cfx_seekablestreamproxy.h b/core/fxcrt/cfx_seekablestreamproxy.h index b169606..bfff049 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.h +++ b/core/fxcrt/cfx_seekablestreamproxy.h
@@ -7,6 +7,7 @@ #ifndef CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ #define CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ +#include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_stream.h" #include "core/fxcrt/fx_system.h" #include "core/fxcrt/retain_ptr.h" @@ -38,10 +39,10 @@ void Seek(From eSeek, FX_FILESIZE iOffset); size_t ReadData(uint8_t* pBuffer, size_t iBufferSize); - uint16_t m_wCodePage; - size_t m_wBOMLength; - FX_FILESIZE m_iPosition; - RetainPtr<IFX_SeekableReadStream> m_pStream; + uint16_t m_wCodePage = FX_CODEPAGE_DefANSI; + size_t m_wBOMLength = 0; + FX_FILESIZE m_iPosition = 0; + RetainPtr<IFX_SeekableReadStream> const m_pStream; }; #endif // CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp index b85d4e9..cbb799e 100644 --- a/core/fxcrt/css/cfx_cssrulecollection.cpp +++ b/core/fxcrt/css/cfx_cssrulecollection.cpp
@@ -15,7 +15,7 @@ #include "core/fxcrt/css/cfx_cssstylesheet.h" #include "core/fxcrt/css/cfx_csssyntaxparser.h" -CFX_CSSRuleCollection::CFX_CSSRuleCollection() : m_iSelectors(0) {} +CFX_CSSRuleCollection::CFX_CSSRuleCollection() = default; CFX_CSSRuleCollection::~CFX_CSSRuleCollection() { Clear();
diff --git a/core/fxcrt/css/cfx_cssrulecollection.h b/core/fxcrt/css/cfx_cssrulecollection.h index 72ae58c..7b6d652 100644 --- a/core/fxcrt/css/cfx_cssrulecollection.h +++ b/core/fxcrt/css/cfx_cssrulecollection.h
@@ -43,7 +43,7 @@ CFX_CSSStyleRule* pRule); std::map<uint32_t, std::vector<std::unique_ptr<Data>>> m_TagRules; - int32_t m_iSelectors; + int32_t m_iSelectors = 0; }; #endif // CORE_FXCRT_CSS_CFX_CSSRULECOLLECTION_H_
diff --git a/core/fxcrt/string_data_template.cpp b/core/fxcrt/string_data_template.cpp index 7b0edfb..ad87af6 100644 --- a/core/fxcrt/string_data_template.cpp +++ b/core/fxcrt/string_data_template.cpp
@@ -90,7 +90,7 @@ template <typename CharType> StringDataTemplate<CharType>::StringDataTemplate(size_t dataLen, size_t allocLen) - : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) { + : m_nDataLength(dataLen), m_nAllocLength(allocLen) { DCHECK(dataLen >= 0); DCHECK(dataLen <= allocLen); m_String[dataLen] = 0;
diff --git a/core/fxcrt/string_data_template.h b/core/fxcrt/string_data_template.h index da471af..8370186 100644 --- a/core/fxcrt/string_data_template.h +++ b/core/fxcrt/string_data_template.h
@@ -33,13 +33,13 @@ // Since the count increments with each new pointer, the largest value is // the number of pointers that can fit into the address space. The size of // the address space itself is a good upper bound on it. - intptr_t m_nRefs; + intptr_t m_nRefs = 0; // These lengths are in terms of number of characters, not bytes, and do not // include the terminating NUL character, but the underlying buffer is sized // to be capable of holding it. size_t m_nDataLength; - size_t m_nAllocLength; + const size_t m_nAllocLength; // Not really 1, variable size. CharType m_String[1];
diff --git a/core/fxcrt/weak_ptr_unittest.cpp b/core/fxcrt/weak_ptr_unittest.cpp index f4026fb..e2a2337 100644 --- a/core/fxcrt/weak_ptr_unittest.cpp +++ b/core/fxcrt/weak_ptr_unittest.cpp
@@ -19,7 +19,7 @@ class PseudoDeletable { public: - PseudoDeletable() : delete_count_(0) {} + PseudoDeletable() = default; void Release() { ++delete_count_; next_.Reset(); @@ -28,7 +28,7 @@ int delete_count() const { return delete_count_; } private: - int delete_count_; + int delete_count_ = 0; WeakTestPtr next_; };
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp index 787bbee..6109370 100644 --- a/core/fxge/cfx_folderfontinfo.cpp +++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -413,6 +413,4 @@ m_FaceName(faceName), m_FontTables(fontTables), m_FontOffset(fontOffset), - m_FileSize(fileSize), - m_Styles(0), - m_Charsets(0) {} + m_FileSize(fileSize) {}
diff --git a/core/fxge/cfx_folderfontinfo.h b/core/fxge/cfx_folderfontinfo.h index e05dae2..05e8fb7 100644 --- a/core/fxge/cfx_folderfontinfo.h +++ b/core/fxge/cfx_folderfontinfo.h
@@ -60,8 +60,8 @@ const ByteString m_FontTables; const uint32_t m_FontOffset; const uint32_t m_FileSize; - uint32_t m_Styles; - uint32_t m_Charsets; + uint32_t m_Styles = 0; + uint32_t m_Charsets = 0; }; void ScanPath(const ByteString& path);
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp index 30248ff..493e449 100644 --- a/core/fxge/dib/cfx_dibbase.cpp +++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -65,11 +65,11 @@ std::vector<uint32_t> m_Palette; // (Amount, Color) pairs std::vector<std::pair<uint32_t, uint32_t>> m_Luts; - int m_lut; + int m_lut = 0; }; CFX_Palette::CFX_Palette(const RetainPtr<CFX_DIBBase>& pBitmap) - : m_Palette(256), m_Luts(4096), m_lut(0) { + : m_Palette(256), m_Luts(4096) { int bpp = pBitmap->GetBPP() / 8; int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight();
diff --git a/core/fxge/win32/cgdi_plus_ext.cpp b/core/fxge/win32/cgdi_plus_ext.cpp index 2d43e7b..1b508c2 100644 --- a/core/fxge/win32/cgdi_plus_ext.cpp +++ b/core/fxge/win32/cgdi_plus_ext.cpp
@@ -468,7 +468,7 @@ class GpStream final : public IStream { public: - GpStream() : m_RefCount(1), m_ReadPos(0) {} + GpStream() = default; ~GpStream() = default; // IUnknown @@ -597,8 +597,8 @@ } private: - LONG m_RefCount; - std::streamoff m_ReadPos; + LONG m_RefCount = 1; + std::streamoff m_ReadPos = 0; std::ostringstream m_InterStream; };
diff --git a/testing/image_diff/image_diff.cpp b/testing/image_diff/image_diff.cpp index 4afbc77..23109af 100644 --- a/testing/image_diff/image_diff.cpp +++ b/testing/image_diff/image_diff.cpp
@@ -37,7 +37,7 @@ class Image { public: - Image() : w_(0), h_(0) {} + Image() = default; Image(const Image& image) : w_(image.w_), h_(image.h_), data_(image.data_) {} bool has_image() const { return w_ > 0 && h_ > 0; } @@ -108,8 +108,8 @@ size_t pixel_address(int x, int y) const { return (y * w_ + x) * 4; } // Pixel dimensions of the image. - int w_; - int h_; + int w_ = 0; + int h_ = 0; std::vector<uint8_t> data_; };
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp index bba7988..29365c7 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp
@@ -7,7 +7,6 @@ #include "xfa/fde/cfde_texteditengine.h" #include <algorithm> -#include <limits> #include <utility> #include "core/fxcrt/fx_extension.h" @@ -20,10 +19,6 @@ namespace { -constexpr size_t kMaxEditOperations = 128; -constexpr size_t kGapSize = 128; -constexpr size_t kPageWidthMax = 0xffff; - class InsertOperation final : public CFDE_TextEditEngine::Operation { public: InsertOperation(CFDE_TextEditEngine* engine, @@ -123,32 +118,7 @@ } // namespace -CFDE_TextEditEngine::CFDE_TextEditEngine() - : font_color_(0xff000000), - font_size_(10.0f), - line_spacing_(10.0f), - text_length_(0), - gap_position_(0), - gap_size_(kGapSize), - available_width_(kPageWidthMax), - character_limit_(std::numeric_limits<size_t>::max()), - visible_line_count_(1), - next_operation_index_to_undo_(kMaxEditOperations - 1), - next_operation_index_to_insert_(0), - max_edit_operations_(kMaxEditOperations), - character_alignment_(CFX_TxtLineAlignment_Left), - has_character_limit_(false), - is_comb_text_(false), - is_dirty_(false), - validation_enabled_(false), - is_multiline_(false), - is_linewrap_enabled_(false), - limit_horizontal_area_(false), - limit_vertical_area_(false), - password_mode_(false), - password_alias_(L'*'), - has_selection_(false), - selection_({0, 0}) { +CFDE_TextEditEngine::CFDE_TextEditEngine() { content_.resize(gap_size_); operation_buffer_.resize(max_edit_operations_); @@ -1219,7 +1189,7 @@ } CFDE_TextEditEngine::Iterator::Iterator(const CFDE_TextEditEngine* engine) - : engine_(engine), current_position_(-1) {} + : engine_(engine) {} CFDE_TextEditEngine::Iterator::~Iterator() = default;
diff --git a/xfa/fde/cfde_texteditengine.h b/xfa/fde/cfde_texteditengine.h index dd039a0..58948b1 100644 --- a/xfa/fde/cfde_texteditengine.h +++ b/xfa/fde/cfde_texteditengine.h
@@ -7,6 +7,7 @@ #ifndef XFA_FDE_CFDE_TEXTEDITENGINE_H_ #define XFA_FDE_CFDE_TEXTEDITENGINE_H_ +#include <limits> #include <memory> #include <utility> #include <vector> @@ -51,8 +52,8 @@ bool IsEOF(bool bPrev) const; private: - UnownedPtr<const CFDE_TextEditEngine> engine_; - int32_t current_position_; + UnownedPtr<const CFDE_TextEditEngine> const engine_; + int32_t current_position_ = -1; }; class Operation { @@ -183,6 +184,15 @@ void SetMaxEditOperationsForTesting(size_t max); private: + struct Selection { + size_t start_idx; + size_t count; + }; + + static constexpr size_t kGapSize = 128; + static constexpr size_t kMaxEditOperations = 128; + static constexpr size_t kPageWidthMax = 0xffff; + void SetCombTextWidth(); void AdjustGap(size_t idx, size_t length); void RebuildPieces(); @@ -198,50 +208,45 @@ } std::vector<CFX_RectF> GetCharRects(const FDE_TEXTEDITPIECE& piece); - struct Selection { - size_t start_idx; - size_t count; - }; - CFX_RectF contents_bounding_box_; UnownedPtr<Delegate> delegate_; std::vector<FDE_TEXTEDITPIECE> text_piece_info_; std::vector<size_t> char_widths_; CFGAS_TxtBreak text_break_; RetainPtr<CFGAS_GEFont> font_; - FX_ARGB font_color_; - float font_size_; - float line_spacing_; + FX_ARGB font_color_ = 0xff000000; + float font_size_ = 10.0f; + float line_spacing_ = 10.0f; std::vector<WideString::CharType> content_; - size_t text_length_; + size_t text_length_ = 0; // See e.g. https://en.wikipedia.org/wiki/Gap_buffer - size_t gap_position_; - size_t gap_size_; + size_t gap_position_ = 0; + size_t gap_size_ = kGapSize; - size_t available_width_; - size_t character_limit_; - size_t visible_line_count_; + size_t available_width_ = kPageWidthMax; + size_t character_limit_ = std::numeric_limits<size_t>::max(); + size_t visible_line_count_ = 1; // Ring buffer of edit operations std::vector<std::unique_ptr<Operation>> operation_buffer_; // Next edit operation to undo. - size_t next_operation_index_to_undo_; + size_t next_operation_index_to_undo_ = kMaxEditOperations - 1; // Next index to insert an edit operation into. - size_t next_operation_index_to_insert_; - size_t max_edit_operations_; - uint32_t character_alignment_; - bool has_character_limit_; - bool is_comb_text_; - bool is_dirty_; - bool validation_enabled_; - bool is_multiline_; - bool is_linewrap_enabled_; - bool limit_horizontal_area_; - bool limit_vertical_area_; - bool password_mode_; - wchar_t password_alias_; - bool has_selection_; - Selection selection_; + size_t next_operation_index_to_insert_ = 0; + size_t max_edit_operations_ = kMaxEditOperations; + uint32_t character_alignment_ = CFX_TxtLineAlignment_Left; + bool has_character_limit_ = false; + bool is_comb_text_ = false; + bool is_dirty_ = false; + bool validation_enabled_ = false; + bool is_multiline_ = false; + bool is_linewrap_enabled_ = false; + bool limit_horizontal_area_ = false; + bool limit_vertical_area_ = false; + bool password_mode_ = false; + wchar_t password_alias_ = L'*'; + bool has_selection_ = false; + Selection selection_{0, 0}; }; #endif // XFA_FDE_CFDE_TEXTEDITENGINE_H_
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 9a45efc..af46421 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -599,8 +599,7 @@ } // namespace -CFGAS_FontDescriptor::CFGAS_FontDescriptor() - : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} +CFGAS_FontDescriptor::CFGAS_FontDescriptor() = default; CFGAS_FontDescriptor::~CFGAS_FontDescriptor() = default;
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 4b5d59e..ac7171b 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -68,12 +68,12 @@ CFGAS_FontDescriptor(); ~CFGAS_FontDescriptor(); - int32_t m_nFaceIndex; - uint32_t m_dwFontStyles; + int32_t m_nFaceIndex = 0; + uint32_t m_dwFontStyles = 0; WideString m_wsFaceName; std::vector<WideString> m_wsFamilyNames; - uint32_t m_dwUsb[4]; - uint32_t m_dwCsb[2]; + uint32_t m_dwUsb[4] = {}; + uint32_t m_dwCsb[2] = {}; }; class CFGAS_FontDescriptorInfo {