1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +00:00

LibArchive: Default initialize member variables

Problem:
- `memset` is used to initialize data instead of using default
  initialization.

Solution:
- Default initialize all member variables.
- Eliminate use of `memset` in favor of C++ braced initialization.
This commit is contained in:
Lenny Maiorani 2022-02-15 10:16:31 -07:00 committed by Idan Horowitz
parent 847efd8aca
commit deba345ca7
2 changed files with 18 additions and 20 deletions

View file

@ -117,22 +117,22 @@ public:
void calculate_checksum();
private:
char m_filename[100];
char m_mode[8];
char m_uid[8];
char m_gid[8];
char m_size[12];
char m_timestamp[12];
char m_checksum[8]; // an uninitialized header's checksum is filled with spaces
char m_type_flag;
char m_link_name[100];
char m_magic[6];
char m_version[2];
char m_owner_name[32];
char m_group_name[32];
char m_major[8];
char m_minor[8];
char m_prefix[155]; // zero out the prefix for archiving
char m_filename[100] { 0 };
char m_mode[8] { 0 };
char m_uid[8] { 0 };
char m_gid[8] { 0 };
char m_size[12] { 0 };
char m_timestamp[12] { 0 };
char m_checksum[8] { 0 }; // an uninitialized header's checksum is filled with spaces
char m_type_flag { 0 };
char m_link_name[100] { 0 };
char m_magic[6] { 0 };
char m_version[2] { 0 };
char m_owner_name[32] { 0 };
char m_group_name[32] { 0 };
char m_major[8] { 0 };
char m_minor[8] { 0 };
char m_prefix[155] { 0 }; // zero out the prefix for archiving
};
}

View file

@ -131,8 +131,7 @@ TarOutputStream::TarOutputStream(OutputStream& stream)
void TarOutputStream::add_directory(const String& path, mode_t mode)
{
VERIFY(!m_finished);
TarFileHeader header;
memset(&header, 0, sizeof(header));
TarFileHeader header {};
header.set_size(0);
header.set_filename(String::formatted("{}/", path)); // Old tar implementations assume directory names end with a /
header.set_type_flag(TarFileType::Directory);
@ -148,8 +147,7 @@ void TarOutputStream::add_directory(const String& path, mode_t mode)
void TarOutputStream::add_file(const String& path, mode_t mode, ReadonlyBytes bytes)
{
VERIFY(!m_finished);
TarFileHeader header;
memset(&header, 0, sizeof(header));
TarFileHeader header {};
header.set_size(bytes.size());
header.set_filename(path);
header.set_type_flag(TarFileType::NormalFile);