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:
@@ -128,7 +128,9 @@ class wxTarHeaderBlock
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTarHeaderBlock()
|
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 Read(wxInputStream& in);
|
||||||
bool Write(wxOutputStream& out);
|
bool Write(wxOutputStream& out);
|
||||||
@@ -1186,7 +1188,7 @@ bool wxTarOutputStream::CloseEntry()
|
|||||||
if (IsOk()) {
|
if (IsOk()) {
|
||||||
wxFileOffset size = RoundUpSize(m_pos);
|
wxFileOffset size = RoundUpSize(m_pos);
|
||||||
if (size > 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_parent_o_stream->Write(m_hdr, size - m_pos);
|
||||||
m_lasterror = m_parent_o_stream->GetLastError();
|
m_lasterror = m_parent_o_stream->GetLastError();
|
||||||
}
|
}
|
||||||
@@ -1210,7 +1212,7 @@ bool wxTarOutputStream::Close()
|
|||||||
if (!CloseEntry() || (m_tarsize == 0 && m_endrecWritten))
|
if (!CloseEntry() || (m_tarsize == 0 && m_endrecWritten))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
memset(m_hdr, 0, sizeof(*m_hdr));
|
m_hdr->Clear();
|
||||||
int count = (RoundUpSize(m_tarsize + 2 * TAR_BLOCKSIZE, m_BlockingFactor)
|
int count = (RoundUpSize(m_tarsize + 2 * TAR_BLOCKSIZE, m_BlockingFactor)
|
||||||
- m_tarsize) / TAR_BLOCKSIZE;
|
- m_tarsize) / TAR_BLOCKSIZE;
|
||||||
while (count--)
|
while (count--)
|
||||||
@@ -1225,7 +1227,7 @@ bool wxTarOutputStream::Close()
|
|||||||
|
|
||||||
bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry)
|
bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry)
|
||||||
{
|
{
|
||||||
memset(m_hdr, 0, sizeof(*m_hdr));
|
m_hdr->Clear();
|
||||||
|
|
||||||
SetHeaderPath(entry.GetName(wxPATH_UNIX));
|
SetHeaderPath(entry.GetName(wxPATH_UNIX));
|
||||||
|
|
||||||
@@ -1271,7 +1273,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry)
|
|||||||
// so prepare a regular header block for the pseudo-file.
|
// so prepare a regular header block for the pseudo-file.
|
||||||
if (!m_hdr2)
|
if (!m_hdr2)
|
||||||
m_hdr2 = new wxTarHeaderBlock;
|
m_hdr2 = new wxTarHeaderBlock;
|
||||||
memset(m_hdr2, 0, sizeof(*m_hdr2));
|
m_hdr2->Clear();
|
||||||
|
|
||||||
// an old tar that doesn't understand extended headers will
|
// an old tar that doesn't understand extended headers will
|
||||||
// extract it as a file, so give these fields reasonable values
|
// extract it as a file, so give these fields reasonable values
|
||||||
|
Reference in New Issue
Block a user