Add wxTarHeaderBlock::Clear() method encapsulating memset()
Using memset() with objects of (non-trivial) class type results in a -Wclass-memaccess warning with g++ 8, so avoid doing this. Add a Clear() method allowing to do the same thing without breaking encapsulation.
This commit is contained in:
parent
d8200f1096
commit
e54ec6c191
@ -128,7 +128,9 @@ class wxTarHeaderBlock
|
||||
{
|
||||
public:
|
||||
wxTarHeaderBlock()
|
||||
{ memset(data, 0, sizeof(data)); }
|
||||
{ Clear(); }
|
||||
|
||||
void Clear(size_t len = 0) { memset(data, 0, len ? len : sizeof(data)); }
|
||||
|
||||
bool Read(wxInputStream& in);
|
||||
bool Write(wxOutputStream& out);
|
||||
@ -1186,7 +1188,7 @@ bool wxTarOutputStream::CloseEntry()
|
||||
if (IsOk()) {
|
||||
wxFileOffset size = RoundUpSize(m_pos);
|
||||
if (size > m_pos) {
|
||||
memset(m_hdr, 0, size - m_pos);
|
||||
m_hdr->Clear(size - m_pos);
|
||||
m_parent_o_stream->Write(m_hdr, size - m_pos);
|
||||
m_lasterror = m_parent_o_stream->GetLastError();
|
||||
}
|
||||
@ -1210,7 +1212,7 @@ bool wxTarOutputStream::Close()
|
||||
if (!CloseEntry() || (m_tarsize == 0 && m_endrecWritten))
|
||||
return false;
|
||||
|
||||
memset(m_hdr, 0, sizeof(*m_hdr));
|
||||
m_hdr->Clear();
|
||||
int count = (RoundUpSize(m_tarsize + 2 * TAR_BLOCKSIZE, m_BlockingFactor)
|
||||
- m_tarsize) / TAR_BLOCKSIZE;
|
||||
while (count--)
|
||||
@ -1225,7 +1227,7 @@ bool wxTarOutputStream::Close()
|
||||
|
||||
bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry)
|
||||
{
|
||||
memset(m_hdr, 0, sizeof(*m_hdr));
|
||||
m_hdr->Clear();
|
||||
|
||||
SetHeaderPath(entry.GetName(wxPATH_UNIX));
|
||||
|
||||
@ -1271,7 +1273,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry)
|
||||
// so prepare a regular header block for the pseudo-file.
|
||||
if (!m_hdr2)
|
||||
m_hdr2 = new wxTarHeaderBlock;
|
||||
memset(m_hdr2, 0, sizeof(*m_hdr2));
|
||||
m_hdr2->Clear();
|
||||
|
||||
// an old tar that doesn't understand extended headers will
|
||||
// extract it as a file, so give these fields reasonable values
|
||||
|
Loading…
Reference in New Issue
Block a user