From e54ec6c1915867416b0fd3600809a0ddcbaac331 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 18:05:16 +0200 Subject: [PATCH] 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. --- src/common/tarstrm.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index 247bcc3b18..f2f7109f28 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -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