From eafe0056721d828636be540cddf3c1226f88f334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 16 Dec 2020 15:01:20 +0100 Subject: [PATCH] Fix -Wclass-memaccess warnings We want to clear/memset the padding bytes, not just each member, so using assignment or {} initialization is not an option. To silence the warnings, cast the object pointer to u8* (which is not undefined behavior) to make it explicit to the compiler that we want to fill the object representation. --- Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 6 +++--- Source/Core/VideoBackends/Software/SetupUnit.cpp | 2 +- Source/Core/VideoCommon/BPStructs.cpp | 2 +- Source/Core/VideoCommon/ShaderCache.cpp | 2 +- Source/Core/VideoCommon/VideoBackendBase.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index c12d4e9819..6bf6e1468c 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -931,7 +931,7 @@ GCMemcardRemoveFileRetVal GCMemcard::RemoveFile(u8 index) // index in the direc // here that has an empty file with the filename "Broken File000" where the actual deleted file // was. Determine when exactly this happens and if this is neccessary for anything. - memset(&(UpdatedDir.m_dir_entries[index]), 0xFF, DENTRY_SIZE); + memset(reinterpret_cast(&UpdatedDir.m_dir_entries[index]), 0xFF, DENTRY_SIZE); UpdatedDir.m_update_counter = UpdatedDir.m_update_counter + 1; UpdateDirectory(UpdatedDir); @@ -1623,7 +1623,7 @@ std::pair Header::CalculateSerial() const DEntry::DEntry() { - memset(this, 0xFF, DENTRY_SIZE); + memset(reinterpret_cast(this), 0xFF, DENTRY_SIZE); } std::string DEntry::GCI_FileName() const @@ -1678,7 +1678,7 @@ GCMemcardErrorCode Header::CheckForErrors(u16 card_size_mbits) const Directory::Directory() { - memset(this, 0xFF, BLOCK_SIZE); + memset(reinterpret_cast(this), 0xFF, BLOCK_SIZE); m_update_counter = 0; m_checksum = Common::swap16(0xF003); m_checksum_inv = 0; diff --git a/Source/Core/VideoBackends/Software/SetupUnit.cpp b/Source/Core/VideoBackends/Software/SetupUnit.cpp index 589d404552..3cdbbee614 100644 --- a/Source/Core/VideoBackends/Software/SetupUnit.cpp +++ b/Source/Core/VideoBackends/Software/SetupUnit.cpp @@ -25,7 +25,7 @@ void SetupUnit::Init(u8 primitiveType) OutputVertexData* SetupUnit::GetVertex() { - memset(m_VertWritePointer, 0, sizeof(*m_VertWritePointer)); + memset(reinterpret_cast(m_VertWritePointer), 0, sizeof(*m_VertWritePointer)); return m_VertWritePointer; } diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 585b072727..2376fd0840 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -43,7 +43,7 @@ static const float s_gammaLUT[] = {1.0f, 1.7f, 2.2f, 1.0f}; void BPInit() { - memset(&bpmem, 0, sizeof(bpmem)); + memset(reinterpret_cast(&bpmem), 0, sizeof(bpmem)); bpmem.bpMask = 0xFFFFFF; } diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index f8b4b881f0..7383dc6595 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -188,7 +188,7 @@ template static void SerializePipelineUid(const UidType& uid, SerializedUidType& serialized_uid) { // Convert to disk format. Ensure all padding bytes are zero. - std::memset(&serialized_uid, 0, sizeof(serialized_uid)); + std::memset(reinterpret_cast(&serialized_uid), 0, sizeof(serialized_uid)); serialized_uid.vertex_decl = uid.vertex_format->GetVertexDeclaration(); serialized_uid.vs_uid = uid.vs_uid; serialized_uid.gs_uid = uid.gs_uid; diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index 20f4d116a6..2f7e92664a 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -295,8 +295,8 @@ void VideoBackendBase::DoState(PointerWrap& p) void VideoBackendBase::InitializeShared() { - memset(&g_main_cp_state, 0, sizeof(g_main_cp_state)); - memset(&g_preprocess_cp_state, 0, sizeof(g_preprocess_cp_state)); + memset(reinterpret_cast(&g_main_cp_state), 0, sizeof(g_main_cp_state)); + memset(reinterpret_cast(&g_preprocess_cp_state), 0, sizeof(g_preprocess_cp_state)); memset(texMem, 0, TMEM_SIZE); // do not initialize again for the config window