Skip to content

Commit

Permalink
Merge pull request #11687 from Minty-Meeo/warnings
Browse files Browse the repository at this point in the history
Resolve GCC/Clang Warnings
  • Loading branch information
leoetlino committed Apr 14, 2023
2 parents 5c03b8a + f290191 commit ae18aa0
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 108 deletions.
27 changes: 15 additions & 12 deletions Source/Core/Common/Crypto/bn.cpp
Expand Up @@ -3,42 +3,45 @@

#include "Common/Crypto/bn.h"

#include <cstddef>
#include <cstdio>
#include <cstring>

#include "Common/CommonTypes.h"

static void bn_zero(u8* d, int n)
static void bn_zero(u8* d, const size_t n)
{
std::memset(d, 0, n);
}

static void bn_copy(u8* d, const u8* a, int n)
static void bn_copy(u8* d, const u8* a, const size_t n)
{
std::memcpy(d, a, n);
}

int bn_compare(const u8* a, const u8* b, int n)
int bn_compare(const u8* a, const u8* b, const size_t n)
{
return std::memcmp(a, b, n);
}

void bn_sub_modulus(u8* a, const u8* N, int n)
void bn_sub_modulus(u8* a, const u8* N, const size_t n)
{
u8 c = 0;
for (int i = n - 1; i >= 0; --i)
for (size_t i = n; i > 0;)
{
--i;
u32 dig = N[i] + c;
c = (a[i] < dig);
a[i] -= dig;
}
}

void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n)
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, const size_t n)
{
u8 c = 0;
for (int i = n - 1; i >= 0; --i)
for (size_t i = n; i > 0;)
{
--i;
u32 dig = a[i] + b[i] + c;
c = (dig >= 0x100);
d[i] = dig;
Expand All @@ -51,11 +54,11 @@ void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n)
bn_sub_modulus(d, N, n);
}

void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n)
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, const size_t n)
{
bn_zero(d, n);

for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
for (u8 mask = 0x80; mask != 0; mask >>= 1)
{
Expand All @@ -66,13 +69,13 @@ void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n)
}
}

void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en)
void bn_exp(u8* d, const u8* a, const u8* N, const size_t n, const u8* e, const size_t en)
{
u8 t[512];

bn_zero(d, n);
d[n - 1] = 1;
for (int i = 0; i < en; i++)
for (size_t i = 0; i < en; i++)
{
for (u8 mask = 0x80; mask != 0; mask >>= 1)
{
Expand All @@ -86,7 +89,7 @@ void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en)
}

// only for prime N -- stupid but lazy, see if I care
void bn_inv(u8* d, const u8* a, const u8* N, int n)
void bn_inv(u8* d, const u8* a, const u8* N, const size_t n)
{
u8 t[512], s[512];

Expand Down
14 changes: 8 additions & 6 deletions Source/Core/Common/Crypto/bn.h
Expand Up @@ -3,13 +3,15 @@

#pragma once

#include <cstddef>

#include "Common/CommonTypes.h"

// bignum arithmetic

int bn_compare(const u8* a, const u8* b, int n);
void bn_sub_modulus(u8* a, const u8* N, int n);
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n);
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n);
void bn_inv(u8* d, const u8* a, const u8* N, int n); // only for prime N
void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en);
int bn_compare(const u8* a, const u8* b, size_t n);
void bn_sub_modulus(u8* a, const u8* N, size_t n);
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, size_t n);
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, size_t n);
void bn_inv(u8* d, const u8* a, const u8* N, size_t n); // only for prime N
void bn_exp(u8* d, const u8* a, const u8* N, size_t n, const u8* e, size_t en);
2 changes: 1 addition & 1 deletion Source/Core/Common/FileUtil.cpp
Expand Up @@ -486,7 +486,7 @@ FSTEntry ScanDirectoryTree(std::string directory, bool recursive)
}
else if (cur_depth < prev_depth)
{
while (dir_fsts.size() - 1 != cur_depth)
while (dir_fsts.size() != static_cast<size_t>(cur_depth) + 1u)
{
calc_dir_size(dir_fsts.top());
dir_fsts.pop();
Expand Down
13 changes: 7 additions & 6 deletions Source/Core/Common/HttpRequest.cpp
Expand Up @@ -33,8 +33,8 @@ class HttpRequest::Impl final
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
size_t size, AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only);

static int CurlProgressCallback(Impl* impl, double dlnow, double dltotal, double ulnow,
double ultotal);
static int CurlProgressCallback(Impl* impl, curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow);
std::string EscapeComponent(const std::string& string);

private:
Expand Down Expand Up @@ -95,11 +95,12 @@ HttpRequest::Response HttpRequest::Post(const std::string& url, const std::strin
reinterpret_cast<const u8*>(payload.data()), payload.size(), codes);
}

int HttpRequest::Impl::CurlProgressCallback(Impl* impl, double dlnow, double dltotal, double ulnow,
double ultotal)
int HttpRequest::Impl::CurlProgressCallback(Impl* impl, curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
// Abort if callback isn't true
return !impl->m_callback(dlnow, dltotal, ulnow, ultotal);
return !impl->m_callback(static_cast<s64>(dltotal), static_cast<s64>(dlnow),
static_cast<s64>(ultotal), static_cast<s64>(ulnow));
}

HttpRequest::Impl::Impl(std::chrono::milliseconds timeout_ms, ProgressCallback callback)
Expand All @@ -116,7 +117,7 @@ HttpRequest::Impl::Impl(std::chrono::milliseconds timeout_ms, ProgressCallback c
if (m_callback)
{
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSDATA, this);
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSFUNCTION, CurlProgressCallback);
curl_easy_setopt(m_curl.get(), CURLOPT_XFERINFOFUNCTION, CurlProgressCallback);
}

// Set up error buffer
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Common/HttpRequest.h
Expand Up @@ -25,8 +25,7 @@ class HttpRequest final
};

// Return false to abort the request
using ProgressCallback =
std::function<bool(double dlnow, double dltotal, double ulnow, double ultotal)>;
using ProgressCallback = std::function<bool(s64 dltotal, s64 dlnow, s64 ultotal, s64 ulnow)>;

explicit HttpRequest(std::chrono::milliseconds timeout_ms = std::chrono::milliseconds{3000},
ProgressCallback callback = nullptr);
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/Common/SettingsHandler.cpp
Expand Up @@ -70,12 +70,10 @@ std::string SettingsHandler::GetValue(std::string_view key) const

void SettingsHandler::Decrypt()
{
const u8* str = m_buffer.data();
while (m_position < m_buffer.size())
{
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
m_position++;
str++;
m_key = (m_key >> 31) | (m_key << 1);
}

Expand Down
12 changes: 4 additions & 8 deletions Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Expand Up @@ -6,6 +6,7 @@
#include <algorithm>
#include <cstring>
#include <mutex>
#include <type_traits>

#include "Common/Assert.h"
#include "Common/CommonTypes.h"
Expand Down Expand Up @@ -101,14 +102,9 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file,
part_start = offset;
// Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after
// primitive data, and the first opcode might update cpmem
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memcpy(&cpmem, &analyzer.m_cpmem, sizeof(CPState));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static_assert(std::is_trivially_copyable_v<CPState>);
std::memcpy(static_cast<void*>(&cpmem), static_cast<const void*>(&analyzer.m_cpmem),
sizeof(CPState));
}
if (analyzer.m_end_of_primitives)
{
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/Core/FifoPlayer/FifoRecorder.cpp
Expand Up @@ -268,9 +268,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
RecordInitialVideoMemory();
}

auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
const auto& fifo = command_processor.GetFifo();
const auto& fifo = Core::System::GetInstance().GetCommandProcessor().GetFifo();
EndFrame(fifo.CPBase.load(std::memory_order_relaxed),
fifo.CPEnd.load(std::memory_order_relaxed));
},
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/Core/HW/DSPHLE/UCodes/AESnd.cpp
Expand Up @@ -44,21 +44,21 @@ constexpr u32 VOICE_16_BIT_FLAG = 2;

// These are used in the pre-2020 versions version
constexpr u32 VOICE_PAUSE_OLD = 0x00000004;
constexpr u32 VOICE_LOOP_OLD = 0x00000008; // not used by the DSP
constexpr u32 VOICE_ONCE_OLD = 0x00000010; // not used by the DSP
constexpr u32 VOICE_STREAM_OLD = 0x00000020; // not used by the DSP
constexpr u32 VOICE_LOOP_OLD [[maybe_unused]] = 0x00000008; // not used by the DSP
constexpr u32 VOICE_ONCE_OLD [[maybe_unused]] = 0x00000010; // not used by the DSP
constexpr u32 VOICE_STREAM_OLD [[maybe_unused]] = 0x00000020; // not used by the DSP

// These were changed in the 2020 version to account for the different flags
constexpr u32 VOICE_PAUSE_NEW = 0x00000008;
constexpr u32 VOICE_LOOP_NEW = 0x00000010; // not used by the DSP
constexpr u32 VOICE_ONCE_NEW = 0x00000020; // not used by the DSP
constexpr u32 VOICE_STREAM_NEW = 0x00000040; // not used by the DSP
constexpr u32 VOICE_LOOP_NEW [[maybe_unused]] = 0x00000010; // not used by the DSP
constexpr u32 VOICE_ONCE_NEW [[maybe_unused]] = 0x00000020; // not used by the DSP
constexpr u32 VOICE_STREAM_NEW [[maybe_unused]] = 0x00000040; // not used by the DSP

// These did not change between versions
constexpr u32 VOICE_FINISHED = 0x00100000;
constexpr u32 VOICE_STOPPED = 0x00200000; // not used by the DSP
constexpr u32 VOICE_STOPPED [[maybe_unused]] = 0x00200000; // not used by the DSP
constexpr u32 VOICE_RUNNING = 0x40000000;
constexpr u32 VOICE_USED = 0x80000000; // not used by the DSP
constexpr u32 VOICE_USED [[maybe_unused]] = 0x80000000; // not used by the DSP

// 1<<4 = scale gain by 1/1, 2<<2 = PCM decoding from ARAM, 1<<0 = 8-bit reads
constexpr u32 ACCELERATOR_FORMAT_8_BIT = 0x0019;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp
Expand Up @@ -384,7 +384,8 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
if (size > 0)
{
// only if contain data
if (static_cast<int>(this_seq - ref->ack_num) >= 0 && data.size() >= size)
if (static_cast<int>(this_seq - ref->ack_num) >= 0 &&
data.size() >= static_cast<size_t>(size))
{
ref->tcp_socket.send(data.data(), size);
ref->ack_num += size;
Expand Down
9 changes: 1 addition & 8 deletions Source/Core/Core/HW/MemoryInterface.cpp
Expand Up @@ -61,14 +61,7 @@ MemoryInterfaceManager::~MemoryInterfaceManager() = default;
void MemoryInterfaceManager::Init()
{
static_assert(std::is_trivially_copyable_v<MIMemStruct>);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memset(&m_mi_mem, 0, sizeof(MIMemStruct));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::memset(static_cast<void*>(&m_mi_mem), 0, sizeof(MIMemStruct));
}

void MemoryInterfaceManager::Shutdown()
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/ProcessorInterface.cpp
Expand Up @@ -24,8 +24,8 @@

namespace ProcessorInterface
{
constexpr u32 FLIPPER_REV_A = 0x046500B0;
constexpr u32 FLIPPER_REV_B = 0x146500B1;
constexpr u32 FLIPPER_REV_A [[maybe_unused]] = 0x046500B0;
constexpr u32 FLIPPER_REV_B [[maybe_unused]] = 0x146500B1;
constexpr u32 FLIPPER_REV_C = 0x246500B1;

ProcessorInterfaceManager::ProcessorInterfaceManager(Core::System& system) : m_system(system)
Expand Down
10 changes: 2 additions & 8 deletions Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.cpp
Expand Up @@ -136,14 +136,8 @@ static bool DeserializeExtensionState(DesiredWiimoteState* state,
return false;
auto& e = state->extension.data.emplace<T>();
static_assert(std::is_trivially_copyable_v<T>);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memcpy(&e, &serialized.data[offset], sizeof(T));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::memcpy(static_cast<void*>(&e), static_cast<const void*>(&serialized.data[offset]),
sizeof(T));
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/NetPlayClient.cpp
Expand Up @@ -254,7 +254,8 @@ bool NetPlayClient::Connect()
// TODO: make this not hang
ENetEvent netEvent;
int net;
while ((net = enet_host_service(m_client, &netEvent, 5000)) > 0 && netEvent.type == 42)
while ((net = enet_host_service(m_client, &netEvent, 5000)) > 0 &&
netEvent.type == ENetEventType(42)) // See PR #11381 and ENetUtil::InterceptCallback
{
// ignore packets from traversal server
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Expand Up @@ -891,7 +891,7 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
auto* copy_hex = menu->addAction(tr("Copy Hex"), this, [this, addr] { OnCopyHex(addr); });
copy_hex->setEnabled(item_has_value);

auto* copy_value = menu->addAction(tr("Copy Value"), this, [this, item_selected] {
auto* copy_value = menu->addAction(tr("Copy Value"), this, [item_selected] {
QApplication::clipboard()->setText(item_selected->text());
});
copy_value->setEnabled(item_has_value);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Main.cpp
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char* argv[])
// code, which makes mouse inputs work again.
// For more information: https://bugs.dolphin-emu.org/issues/12913
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
putenv("QT_XCB_NO_XI2=1");
setenv("QT_XCB_NO_XI2", "1", true);
#endif
#endif

Expand Down
4 changes: 1 addition & 3 deletions Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
Expand Up @@ -3,10 +3,8 @@

#include "InputCommon/ControllerInterface/Xlib/XInput2.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wregister"
#include <X11/XKBlib.h>
#pragma GCC diagnostic pop

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/UpdaterCommon/UpdaterCommon.cpp
Expand Up @@ -58,7 +58,7 @@ void LogToFile(const char* fmt, ...)
va_end(args);
}

bool ProgressCallback(double total, double now, double, double)
bool ProgressCallback(s64 total, s64 now, s64, s64)
{
UI::SetCurrentProgress(static_cast<int>(now), static_cast<int>(total));
return true;
Expand Down
12 changes: 4 additions & 8 deletions Source/Core/VideoCommon/CPMemory.cpp
Expand Up @@ -4,6 +4,7 @@
#include "VideoCommon/CPMemory.h"

#include <cstring>
#include <type_traits>

#include "Common/ChunkFile.h"
#include "Common/Logging/Log.h"
Expand All @@ -17,14 +18,9 @@ CPState g_preprocess_cp_state;

void CopyPreprocessCPStateFromMain()
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
std::memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static_assert(std::is_trivially_copyable_v<CPState>);
std::memcpy(static_cast<void*>(&g_preprocess_cp_state),
static_cast<const void*>(&g_main_cp_state), sizeof(CPState));
}

std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value)
Expand Down

0 comments on commit ae18aa0

Please sign in to comment.