From ab252aedfa95095fe0e9a458e161b164c1156ca7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:00:13 +0200 Subject: [PATCH 1/7] =?UTF-8?q?Core,=20DolphinQt,=20UICommon:=20Fix=20all?= =?UTF-8?q?=20cases=20of=20-Wrange-loop-construct=20in=20gcc=C2=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 7 ++++-- Source/Core/DolphinQt/Resources.cpp | 23 ++++++++++--------- Source/Core/DolphinQt/Resources.h | 11 +++++---- .../Core/DolphinQt/Settings/GameCubePane.cpp | 2 +- Source/Core/UICommon/GameFileCache.cpp | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 4bce44b62e..10aa72c3b5 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -546,8 +546,11 @@ void BluetoothRealDevice::SaveLinkKeys() oss << Common::MacAddressToString(address); oss << '='; oss << std::hex; - for (const u16& data : entry.second) - oss << std::setfill('0') << std::setw(2) << data; + for (u8 data : entry.second) + { + // We cast to u16 here in order to have it displayed as two nibbles. + oss << std::setfill('0') << std::setw(2) << static_cast(data); + } oss << std::dec << ','; } std::string config_string = oss.str(); diff --git a/Source/Core/DolphinQt/Resources.cpp b/Source/Core/DolphinQt/Resources.cpp index e10f8acfd4..2ab51fb536 100644 --- a/Source/Core/DolphinQt/Resources.cpp +++ b/Source/Core/DolphinQt/Resources.cpp @@ -21,9 +21,10 @@ QList Resources::m_platforms; QList Resources::m_countries; QList Resources::m_misc; -QIcon Resources::GetIcon(const QString& name, const QString& dir) +QIcon Resources::GetIcon(std::string_view name, const QString& dir) { - QString base_path = dir + QLatin1Char{'/'} + name; + QString name_owned = QString::fromLatin1(name.data(), static_cast(name.size())); + QString base_path = dir + QLatin1Char{'/'} + name_owned; const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio(); @@ -42,7 +43,7 @@ QIcon Resources::GetIcon(const QString& name, const QString& dir) return icon; } -QPixmap Resources::GetPixmap(const QString& name, const QString& dir) +QPixmap Resources::GetPixmap(std::string_view name, const QString& dir) { const auto icon = GetIcon(name, dir); return icon.pixmap(icon.availableSizes()[0]); @@ -58,30 +59,30 @@ static QString GetResourcesDir() return QString::fromStdString(File::GetSysDirectory() + "Resources"); } -QIcon Resources::GetScaledIcon(const std::string& name) +QIcon Resources::GetScaledIcon(std::string_view name) { - return GetIcon(QString::fromStdString(name), GetResourcesDir()); + return GetIcon(name, GetResourcesDir()); } -QIcon Resources::GetScaledThemeIcon(const std::string& name) +QIcon Resources::GetScaledThemeIcon(std::string_view name) { - return GetIcon(QString::fromStdString(name), GetCurrentThemeDir()); + return GetIcon(name, GetCurrentThemeDir()); } -QPixmap Resources::GetScaledPixmap(const std::string& name) +QPixmap Resources::GetScaledPixmap(std::string_view name) { - return GetPixmap(QString::fromStdString(name), GetResourcesDir()); + return GetPixmap(name, GetResourcesDir()); } void Resources::Init() { - for (const std::string& platform : + for (std::string_view platform : {"Platform_Gamecube", "Platform_Wii", "Platform_Wad", "Platform_File"}) { m_platforms.append(GetScaledPixmap(platform)); } - for (const std::string& country : + for (std::string_view country : {"Flag_Europe", "Flag_Japan", "Flag_USA", "Flag_Australia", "Flag_France", "Flag_Germany", "Flag_Italy", "Flag_Korea", "Flag_Netherlands", "Flag_Russia", "Flag_Spain", "Flag_Taiwan", "Flag_International", "Flag_Unknown"}) diff --git a/Source/Core/DolphinQt/Resources.h b/Source/Core/DolphinQt/Resources.h index 923c1bf1d9..67ffc23d4d 100644 --- a/Source/Core/DolphinQt/Resources.h +++ b/Source/Core/DolphinQt/Resources.h @@ -5,6 +5,7 @@ #include #include +#include namespace DiscIO { @@ -30,16 +31,16 @@ public: static QPixmap GetMisc(MiscID id); - static QIcon GetScaledIcon(const std::string& name); - static QIcon GetScaledThemeIcon(const std::string& name); + static QIcon GetScaledIcon(std::string_view name); + static QIcon GetScaledThemeIcon(std::string_view name); static QIcon GetAppIcon(); - static QPixmap GetScaledPixmap(const std::string& name); + static QPixmap GetScaledPixmap(std::string_view name); private: Resources() {} - static QIcon GetIcon(const QString& name, const QString& dir); - static QPixmap GetPixmap(const QString& name, const QString& dir); + static QIcon GetIcon(std::string_view name, const QString& dir); + static QPixmap GetPixmap(std::string_view name, const QString& dir); static QList m_platforms; static QList m_countries; diff --git a/Source/Core/DolphinQt/Settings/GameCubePane.cpp b/Source/Core/DolphinQt/Settings/GameCubePane.cpp index ce45eb54a1..8ec5126f2f 100644 --- a/Source/Core/DolphinQt/Settings/GameCubePane.cpp +++ b/Source/Core/DolphinQt/Settings/GameCubePane.cpp @@ -440,7 +440,7 @@ void GameCubePane::LoadSettings() bool have_menu = false; - for (const std::string& dir : {USA_DIR, JAP_DIR, EUR_DIR}) + for (const std::string dir : {USA_DIR, JAP_DIR, EUR_DIR}) { const auto path = DIR_SEP + dir + DIR_SEP GC_IPL; if (File::Exists(File::GetUserPath(D_GCUSER_IDX) + path) || diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index 30bbca924b..a1b55b3614 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -45,7 +45,7 @@ GameFileCache::GameFileCache() : m_path(File::GetUserPath(D_CACHE_IDX) + "gameli void GameFileCache::ForEach(std::function&)> f) const { - for (const std::shared_ptr& item : m_cached_files) + for (const std::shared_ptr& item : m_cached_files) f(item); } From 3d662e746bef6651dcdd0bc985c9e6d6518f006d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:17:36 +0200 Subject: [PATCH 2/7] =?UTF-8?q?Core:=20Fix=20a=20-Wshadow=20warning=20in?= =?UTF-8?q?=20gcc=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 @@ + From 7e39a0405b79af7c6736830b82734e581084c3a5 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:19:56 +0200 Subject: [PATCH 3/7] =?UTF-8?q?DolphinQt,=20VideoBackends:=20Fix=20all=20c?= =?UTF-8?q?ases=20of=20-Wswitch=20in=20gcc=C2=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Core/DolphinQt/GameList/GameListModel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Core/DolphinQt/GameList/GameListModel.cpp b/Source/Core/DolphinQt/GameList/GameListModel.cpp index 0c9921ba38..487791fbe9 100644 --- a/Source/Core/DolphinQt/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt/GameList/GameListModel.cpp @@ -195,6 +195,8 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const return tags.join(QStringLiteral(", ")); } + default: + break; } return QVariant(); @@ -231,6 +233,8 @@ QVariant GameListModel::headerData(int section, Qt::Orientation orientation, int return tr("Compression"); case Column::Tags: return tr("Tags"); + default: + break; } return QVariant(); } From 25b136ac176ab643e91ce124121722ca67769e45 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:55:03 +0200 Subject: [PATCH 4/7] =?UTF-8?q?VideoCommon:=20Fix=20a=20-Wclass-memaccess?= =?UTF-8?q?=20in=20gcc=C2=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Core/VideoCommon/CommandProcessor.cpp | 31 ++++++++++++++++---- Source/Core/VideoCommon/CommandProcessor.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index 95c157d4e0..bca9f3b21d 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -48,6 +48,30 @@ static void UpdateInterrupts_Wrapper(u64 userdata, s64 cyclesLate) UpdateInterrupts(userdata); } +void SCPFifoStruct::Init() +{ + CPBase = 0; + CPEnd = 0; + CPHiWatermark = 0; + CPLoWatermark = 0; + CPReadWriteDistance = 0; + CPWritePointer = 0; + CPReadPointer = 0; + CPBreakpoint = 0; + SafeCPReadPointer = 0; + + bFF_GPLinkEnable = 0; + bFF_GPReadEnable = 0; + bFF_BPEnable = 0; + bFF_BPInt = 0; + + bFF_Breakpoint.store(0, std::memory_order_relaxed); + bFF_HiWatermark.store(0, std::memory_order_relaxed); + bFF_HiWatermarkInt.store(0, std::memory_order_relaxed); + bFF_LoWatermark.store(0, std::memory_order_relaxed); + bFF_LoWatermarkInt.store(0, std::memory_order_relaxed); +} + void SCPFifoStruct::DoState(PointerWrap& p) { p.Do(CPBase); @@ -117,12 +141,7 @@ void Init() m_tokenReg = 0; - memset(&fifo, 0, sizeof(fifo)); - fifo.bFF_Breakpoint.store(0, std::memory_order_relaxed); - fifo.bFF_HiWatermark.store(0, std::memory_order_relaxed); - fifo.bFF_HiWatermarkInt.store(0, std::memory_order_relaxed); - fifo.bFF_LoWatermark.store(0, std::memory_order_relaxed); - fifo.bFF_LoWatermarkInt.store(0, std::memory_order_relaxed); + fifo.Init(); s_interrupt_set.Clear(); s_interrupt_waiting.Clear(); diff --git a/Source/Core/VideoCommon/CommandProcessor.h b/Source/Core/VideoCommon/CommandProcessor.h index 66ef981cac..4ca73c71d2 100644 --- a/Source/Core/VideoCommon/CommandProcessor.h +++ b/Source/Core/VideoCommon/CommandProcessor.h @@ -40,6 +40,7 @@ struct SCPFifoStruct std::atomic bFF_LoWatermark; std::atomic bFF_HiWatermark; + void Init(); void DoState(PointerWrap& p); }; From 24db6e467a6560126c5e718e40735c62362d3246 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 21:59:44 +0200 Subject: [PATCH 5/7] =?UTF-8?q?DolphinQt:=20Fix=20a=20-Wunused-result=20in?= =?UTF-8?q?=20gcc=C2=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also use the correct error check for other similar calls in the same file, despite nothing being doable on error. --- Source/Core/DolphinQt/QtUtils/SignalDaemon.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt/QtUtils/SignalDaemon.cpp b/Source/Core/DolphinQt/QtUtils/SignalDaemon.cpp index efda873412..c3e6039ccc 100644 --- a/Source/Core/DolphinQt/QtUtils/SignalDaemon.cpp +++ b/Source/Core/DolphinQt/QtUtils/SignalDaemon.cpp @@ -34,8 +34,9 @@ void SignalDaemon::OnNotifierActivated() m_term->setEnabled(false); char tmp; - if (read(s_sigterm_fd[1], &tmp, sizeof(char))) + if (read(s_sigterm_fd[1], &tmp, sizeof(char)) != sizeof(char)) { + // Not much we can do here. } m_term->setEnabled(true); @@ -45,10 +46,14 @@ void SignalDaemon::OnNotifierActivated() void SignalDaemon::HandleInterrupt(int) { - write(STDERR_FILENO, message, sizeof(message)); + if (write(STDERR_FILENO, message, sizeof(message)) != sizeof(message)) + { + // Not much we can do here. + } char a = 1; - if (write(s_sigterm_fd[0], &a, sizeof(a))) + if (write(s_sigterm_fd[0], &a, sizeof(a)) != sizeof(a)) { + // Not much we can do here. } } From 7590f07b80d2ff994912675bc2e3689c5b69bd57 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 17 May 2021 20:38:39 +0200 Subject: [PATCH 6/7] FrameDump: Remove deprecated call to av_init_packet() This function was deprecated in ffmpeg in January[1], while its replacement got introduced in 2015[2], so now might be the time to start using it in Dolphin. :) [1] https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/f7db77bd8785d1715d3e7ed7e69bd1cc991f2d07 [2] https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/a9a60106370f862e191dea58e748626da6a8fe97 --- Source/Core/VideoCommon/FrameDump.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp index ceba863b89..2773c0e0fe 100644 --- a/Source/Core/VideoCommon/FrameDump.cpp +++ b/Source/Core/VideoCommon/FrameDump.cpp @@ -333,12 +333,18 @@ void FrameDump::AddFrame(const FrameData& frame) void FrameDump::ProcessPackets() { + auto pkt = std::unique_ptr>( + av_packet_alloc(), [](AVPacket* packet) { av_packet_free(&packet); }); + + if (!pkt) + { + ERROR_LOG_FMT(FRAMEDUMP, "Could not allocate packet"); + return; + } + while (true) { - AVPacket pkt; - av_init_packet(&pkt); - - const int receive_error = avcodec_receive_packet(m_context->codec, &pkt); + const int receive_error = avcodec_receive_packet(m_context->codec, pkt.get()); if (receive_error == AVERROR(EAGAIN) || receive_error == AVERROR_EOF) { @@ -352,10 +358,10 @@ void FrameDump::ProcessPackets() break; } - av_packet_rescale_ts(&pkt, m_context->codec->time_base, m_context->stream->time_base); - pkt.stream_index = m_context->stream->index; + av_packet_rescale_ts(pkt.get(), m_context->codec->time_base, m_context->stream->time_base); + pkt->stream_index = m_context->stream->index; - if (const int write_error = av_interleaved_write_frame(m_context->format, &pkt)) + if (const int write_error = av_interleaved_write_frame(m_context->format, pkt.get())) { ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", write_error); break; From 5a1333026be53c36dd23a886d66fe779a6853210 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 10 Oct 2021 01:48:23 +0200 Subject: [PATCH 7/7] VideoCommon: Add missing algorithm include for std::none_of Otherwise this is an error on gcc/libstdc++, and there are no transitive includes for this header. --- Source/Core/VideoCommon/BoundingBox.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/VideoCommon/BoundingBox.cpp b/Source/Core/VideoCommon/BoundingBox.cpp index 6411ec94dc..33cffef469 100644 --- a/Source/Core/VideoCommon/BoundingBox.cpp +++ b/Source/Core/VideoCommon/BoundingBox.cpp @@ -3,6 +3,8 @@ #include "VideoCommon/BoundingBox.h" +#include + #include "Common/Assert.h" #include "Common/ChunkFile.h" #include "Common/CommonTypes.h"