From 01330805cb8e316f39c0ef9c9be49eaf0ec26a17 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 24 Sep 2024 00:37:18 -0500 Subject: [PATCH] refactor: prefer member initializers in asar structs (#43883) prefactor: prefer member initializers in asar::Archive prefactor: prefer member initializers in asar::Archive::FileInfo prefactor: prefer member initializers in asar::IntegrityPayload --- shell/common/asar/archive.cc | 9 +++------ shell/common/asar/archive.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/shell/common/asar/archive.cc b/shell/common/asar/archive.cc index 4fb9a70f5ce..34037ecd904 100644 --- a/shell/common/asar/archive.cc +++ b/shell/common/asar/archive.cc @@ -156,17 +156,14 @@ bool FillFileInfoWithNode(Archive::FileInfo* info, } // namespace -IntegrityPayload::IntegrityPayload() - : algorithm(HashAlgorithm::kNone), block_size(0) {} +IntegrityPayload::IntegrityPayload() = default; IntegrityPayload::~IntegrityPayload() = default; IntegrityPayload::IntegrityPayload(const IntegrityPayload& other) = default; -Archive::FileInfo::FileInfo() - : unpacked(false), executable(false), size(0), offset(0) {} +Archive::FileInfo::FileInfo() = default; Archive::FileInfo::~FileInfo() = default; -Archive::Archive(const base::FilePath& path) - : initialized_(false), path_(path), file_(base::File::FILE_OK) { +Archive::Archive(const base::FilePath& path) : path_{path} { electron::ScopedAllowBlockingForElectron allow_blocking; file_.Initialize(path_, base::File::FLAG_OPEN | base::File::FLAG_READ); #if BUILDFLAG(IS_WIN) diff --git a/shell/common/asar/archive.h b/shell/common/asar/archive.h index ed9b18d74c4..16898e1f731 100644 --- a/shell/common/asar/archive.h +++ b/shell/common/asar/archive.h @@ -31,9 +31,9 @@ struct IntegrityPayload { IntegrityPayload(); ~IntegrityPayload(); IntegrityPayload(const IntegrityPayload& other); - HashAlgorithm algorithm; + HashAlgorithm algorithm = HashAlgorithm::kNone; std::string hash; - uint32_t block_size; + uint32_t block_size = 0U; std::vector blocks; }; @@ -44,10 +44,10 @@ class Archive { struct FileInfo { FileInfo(); ~FileInfo(); - bool unpacked; - bool executable; - uint32_t size; - uint64_t offset; + bool unpacked = false; + bool executable = false; + uint32_t size = 0U; + uint64_t offset = 0U; std::optional integrity; }; @@ -100,10 +100,10 @@ class Archive { base::FilePath path() const { return path_; } private: - bool initialized_; + bool initialized_ = false; bool header_validated_ = false; const base::FilePath path_; - base::File file_; + base::File file_{base::File::FILE_OK}; int fd_ = -1; uint32_t header_size_ = 0; std::optional header_;