From d9d5e1d5f7c315e28bd6599a733f9f541a39686c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 17:57:17 +0200 Subject: [PATCH 1/4] Remove unused wxDEFINE_SCOPED_PTR_TYPE(wxTarHeaderBlock) wxTarHeaderBlockPtr defined by this macro was never used, so just remove it. --- src/common/tarstrm.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index f080e759de..a38e3f0715 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -155,8 +155,6 @@ private: static void check(); }; -wxDEFINE_SCOPED_PTR_TYPE(wxTarHeaderBlock) - // A table giving the field names and offsets in a tar header block const wxTarField wxTarHeaderBlock::fields[] = { From 58e6355695e7852864aec255cab539c4ad3d77b7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 17:58:09 +0200 Subject: [PATCH 2/4] Rename wxTarEntryPtr_ to wxTarEntryPtr Remove the unusual underscore at the end of the type and use a single wxDEFINE_SCOPED_PTR_TYPE() macro instead of 2 of them to simplify code. --- src/common/tarstrm.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index a38e3f0715..b8820febd6 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -639,8 +639,7 @@ void wxTarEntry::SetMode(int mode) ///////////////////////////////////////////////////////////////////////////// // Input stream -wxDECLARE_SCOPED_PTR(wxTarEntry, wxTarEntryPtr_) -wxDEFINE_SCOPED_PTR (wxTarEntry, wxTarEntryPtr_) +wxDEFINE_SCOPED_PTR_TYPE(wxTarEntry) wxTarInputStream::wxTarInputStream(wxInputStream& stream, wxMBConv& conv /*=wxConvLocal*/) @@ -683,7 +682,7 @@ wxTarEntry *wxTarInputStream::GetNextEntry() if (!IsOk()) return NULL; - wxTarEntryPtr_ entry(new wxTarEntry); + wxTarEntryPtr entry(new wxTarEntry); entry->SetMode(GetHeaderNumber(TAR_MODE)); entry->SetUserId(GetHeaderNumber(TAR_UID)); @@ -1099,7 +1098,7 @@ wxTarOutputStream::~wxTarOutputStream() bool wxTarOutputStream::PutNextEntry(wxTarEntry *entry) { - wxTarEntryPtr_ e(entry); + wxTarEntryPtr e(entry); if (!CloseEntry()) return false; From d8200f109617c0434b6aaba7afa3cefa48c549e3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 17:59:20 +0200 Subject: [PATCH 3/4] Remove unused wxTarHeaderBlock copy ctor These objects are never copied, and if they were, the default (compiler-generated) copy ctor would do the same thing this explicitly defined copy ctor did, so just remove it. --- src/common/tarstrm.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index b8820febd6..247bcc3b18 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -129,8 +129,6 @@ class wxTarHeaderBlock public: wxTarHeaderBlock() { memset(data, 0, sizeof(data)); } - wxTarHeaderBlock(const wxTarHeaderBlock& hb) - { memcpy(data, hb.data, sizeof(data)); } bool Read(wxInputStream& in); bool Write(wxOutputStream& out); From e54ec6c1915867416b0fd3600809a0ddcbaac331 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 18:05:16 +0200 Subject: [PATCH 4/4] 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