From 3d662e746bef6651dcdd0bc985c9e6d6518f006d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:17:36 +0200 Subject: [PATCH] =?UTF-8?q?Core:=20Fix=20a=20-Wshadow=20warning=20in=20gcc?= =?UTF-8?q?=C2=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This moves the only direct call to zlib’s crc32() into its own translation unit, but that operation is cold enough that this won’t matter in the slightest. crc32_z() would be more appropriate, but Android has an older zlib version… --- Source/Core/Common/CMakeLists.txt | 2 ++ Source/Core/Common/CRC32.cpp | 19 +++++++++++++++++++ Source/Core/Common/CRC32.h | 11 +++++++++++ Source/Core/Core/Boot/Boot.cpp | 7 ++----- Source/Core/DolphinLib.props | 2 ++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 Source/Core/Common/CRC32.cpp create mode 100644 Source/Core/Common/CRC32.h diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index b1e25af45b..8f3bc99562 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -25,6 +25,8 @@ add_library(common Config/Layer.cpp Config/Layer.h CPUDetect.h + CRC32.cpp + CRC32.h Crypto/AES.cpp Crypto/AES.h Crypto/bn.cpp diff --git a/Source/Core/Common/CRC32.cpp b/Source/Core/Common/CRC32.cpp new file mode 100644 index 0000000000..843b0c3333 --- /dev/null +++ b/Source/Core/Common/CRC32.cpp @@ -0,0 +1,19 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "Common/CRC32.h" + +namespace Common +{ +u32 ComputeCRC32(std::string_view data) +{ + const Bytef* buf = reinterpret_cast(data.data()); + uInt len = static_cast(data.size()); + // Use zlibs crc32 implementation to compute the hash + u32 hash = crc32(0L, Z_NULL, 0); + hash = crc32(hash, buf, len); + return hash; +} +} // namespace Common diff --git a/Source/Core/Common/CRC32.h b/Source/Core/Common/CRC32.h new file mode 100644 index 0000000000..3f3f52b96a --- /dev/null +++ b/Source/Core/Common/CRC32.h @@ -0,0 +1,11 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "Common/CommonTypes.h" + +namespace Common +{ +u32 ComputeCRC32(std::string_view data); +} // namespace Common diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index df7cf9014f..3bb2c5e53d 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -20,10 +20,9 @@ namespace fs = std::filesystem; #include #include -#include - #include "Common/Align.h" #include "Common/CDUtils.h" +#include "Common/CRC32.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/Config/Config.h" @@ -355,9 +354,7 @@ bool CBoot::Load_BS2(const std::string& boot_rom_filename) if (!File::ReadFileToString(boot_rom_filename, data)) return false; - // Use zlibs crc32 implementation to compute the hash - u32 ipl_hash = crc32(0L, Z_NULL, 0); - ipl_hash = crc32(ipl_hash, (const Bytef*)data.data(), (u32)data.size()); + const u32 ipl_hash = Common::ComputeCRC32(data); bool known_ipl = false; bool pal_ipl = false; switch (ipl_hash) diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index fc429c0ab4..96b489f555 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -21,6 +21,7 @@ + @@ -689,6 +690,7 @@ +