refactor: prefer member initializers in asar structs (#43918)

prefactor: prefer member initializers in asar::Archive

prefactor: prefer member initializers in asar::Archive::FileInfo

prefactor: prefer member initializers in asar::IntegrityPayload

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-09-24 10:11:50 +02:00 committed by GitHub
parent d35b848f95
commit cdcfe49592
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 14 deletions

View file

@ -156,17 +156,14 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
} // namespace } // namespace
IntegrityPayload::IntegrityPayload() IntegrityPayload::IntegrityPayload() = default;
: algorithm(HashAlgorithm::kNone), block_size(0) {}
IntegrityPayload::~IntegrityPayload() = default; IntegrityPayload::~IntegrityPayload() = default;
IntegrityPayload::IntegrityPayload(const IntegrityPayload& other) = default; IntegrityPayload::IntegrityPayload(const IntegrityPayload& other) = default;
Archive::FileInfo::FileInfo() Archive::FileInfo::FileInfo() = default;
: unpacked(false), executable(false), size(0), offset(0) {}
Archive::FileInfo::~FileInfo() = default; Archive::FileInfo::~FileInfo() = default;
Archive::Archive(const base::FilePath& path) Archive::Archive(const base::FilePath& path) : path_{path} {
: initialized_(false), path_(path), file_(base::File::FILE_OK) {
electron::ScopedAllowBlockingForElectron allow_blocking; electron::ScopedAllowBlockingForElectron allow_blocking;
file_.Initialize(path_, base::File::FLAG_OPEN | base::File::FLAG_READ); file_.Initialize(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)

View file

@ -31,9 +31,9 @@ struct IntegrityPayload {
IntegrityPayload(); IntegrityPayload();
~IntegrityPayload(); ~IntegrityPayload();
IntegrityPayload(const IntegrityPayload& other); IntegrityPayload(const IntegrityPayload& other);
HashAlgorithm algorithm; HashAlgorithm algorithm = HashAlgorithm::kNone;
std::string hash; std::string hash;
uint32_t block_size; uint32_t block_size = 0U;
std::vector<std::string> blocks; std::vector<std::string> blocks;
}; };
@ -44,10 +44,10 @@ class Archive {
struct FileInfo { struct FileInfo {
FileInfo(); FileInfo();
~FileInfo(); ~FileInfo();
bool unpacked; bool unpacked = false;
bool executable; bool executable = false;
uint32_t size; uint32_t size = 0U;
uint64_t offset; uint64_t offset = 0U;
std::optional<IntegrityPayload> integrity; std::optional<IntegrityPayload> integrity;
}; };
@ -100,10 +100,10 @@ class Archive {
base::FilePath path() const { return path_; } base::FilePath path() const { return path_; }
private: private:
bool initialized_; bool initialized_ = false;
bool header_validated_ = false; bool header_validated_ = false;
const base::FilePath path_; const base::FilePath path_;
base::File file_; base::File file_{base::File::FILE_OK};
int fd_ = -1; int fd_ = -1;
uint32_t header_size_ = 0; uint32_t header_size_ = 0;
std::optional<base::Value::Dict> header_; std::optional<base::Value::Dict> header_;