Skip to content

Commit ae18aa0

Browse files
authored
Merge pull request #11687 from Minty-Meeo/warnings
Resolve GCC/Clang Warnings
2 parents 5c03b8a + f290191 commit ae18aa0

File tree

22 files changed

+75
-108
lines changed

22 files changed

+75
-108
lines changed

Source/Core/Common/Crypto/bn.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@
33

44
#include "Common/Crypto/bn.h"
55

6+
#include <cstddef>
67
#include <cstdio>
78
#include <cstring>
89

910
#include "Common/CommonTypes.h"
1011

11-
static void bn_zero(u8* d, int n)
12+
static void bn_zero(u8* d, const size_t n)
1213
{
1314
std::memset(d, 0, n);
1415
}
1516

16-
static void bn_copy(u8* d, const u8* a, int n)
17+
static void bn_copy(u8* d, const u8* a, const size_t n)
1718
{
1819
std::memcpy(d, a, n);
1920
}
2021

21-
int bn_compare(const u8* a, const u8* b, int n)
22+
int bn_compare(const u8* a, const u8* b, const size_t n)
2223
{
2324
return std::memcmp(a, b, n);
2425
}
2526

26-
void bn_sub_modulus(u8* a, const u8* N, int n)
27+
void bn_sub_modulus(u8* a, const u8* N, const size_t n)
2728
{
2829
u8 c = 0;
29-
for (int i = n - 1; i >= 0; --i)
30+
for (size_t i = n; i > 0;)
3031
{
32+
--i;
3133
u32 dig = N[i] + c;
3234
c = (a[i] < dig);
3335
a[i] -= dig;
3436
}
3537
}
3638

37-
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n)
39+
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, const size_t n)
3840
{
3941
u8 c = 0;
40-
for (int i = n - 1; i >= 0; --i)
42+
for (size_t i = n; i > 0;)
4143
{
44+
--i;
4245
u32 dig = a[i] + b[i] + c;
4346
c = (dig >= 0x100);
4447
d[i] = dig;
@@ -51,11 +54,11 @@ void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n)
5154
bn_sub_modulus(d, N, n);
5255
}
5356

54-
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n)
57+
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, const size_t n)
5558
{
5659
bn_zero(d, n);
5760

58-
for (int i = 0; i < n; i++)
61+
for (size_t i = 0; i < n; i++)
5962
{
6063
for (u8 mask = 0x80; mask != 0; mask >>= 1)
6164
{
@@ -66,13 +69,13 @@ void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n)
6669
}
6770
}
6871

69-
void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en)
72+
void bn_exp(u8* d, const u8* a, const u8* N, const size_t n, const u8* e, const size_t en)
7073
{
7174
u8 t[512];
7275

7376
bn_zero(d, n);
7477
d[n - 1] = 1;
75-
for (int i = 0; i < en; i++)
78+
for (size_t i = 0; i < en; i++)
7679
{
7780
for (u8 mask = 0x80; mask != 0; mask >>= 1)
7881
{
@@ -86,7 +89,7 @@ void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en)
8689
}
8790

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

Source/Core/Common/Crypto/bn.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
#pragma once
55

6+
#include <cstddef>
7+
68
#include "Common/CommonTypes.h"
79

810
// bignum arithmetic
911

10-
int bn_compare(const u8* a, const u8* b, int n);
11-
void bn_sub_modulus(u8* a, const u8* N, int n);
12-
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, int n);
13-
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, int n);
14-
void bn_inv(u8* d, const u8* a, const u8* N, int n); // only for prime N
15-
void bn_exp(u8* d, const u8* a, const u8* N, int n, const u8* e, int en);
12+
int bn_compare(const u8* a, const u8* b, size_t n);
13+
void bn_sub_modulus(u8* a, const u8* N, size_t n);
14+
void bn_add(u8* d, const u8* a, const u8* b, const u8* N, size_t n);
15+
void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, size_t n);
16+
void bn_inv(u8* d, const u8* a, const u8* N, size_t n); // only for prime N
17+
void bn_exp(u8* d, const u8* a, const u8* N, size_t n, const u8* e, size_t en);

Source/Core/Common/FileUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ FSTEntry ScanDirectoryTree(std::string directory, bool recursive)
486486
}
487487
else if (cur_depth < prev_depth)
488488
{
489-
while (dir_fsts.size() - 1 != cur_depth)
489+
while (dir_fsts.size() != static_cast<size_t>(cur_depth) + 1u)
490490
{
491491
calc_dir_size(dir_fsts.top());
492492
dir_fsts.pop();

Source/Core/Common/HttpRequest.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class HttpRequest::Impl final
3333
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
3434
size_t size, AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only);
3535

36-
static int CurlProgressCallback(Impl* impl, double dlnow, double dltotal, double ulnow,
37-
double ultotal);
36+
static int CurlProgressCallback(Impl* impl, curl_off_t dltotal, curl_off_t dlnow,
37+
curl_off_t ultotal, curl_off_t ulnow);
3838
std::string EscapeComponent(const std::string& string);
3939

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

98-
int HttpRequest::Impl::CurlProgressCallback(Impl* impl, double dlnow, double dltotal, double ulnow,
99-
double ultotal)
98+
int HttpRequest::Impl::CurlProgressCallback(Impl* impl, curl_off_t dltotal, curl_off_t dlnow,
99+
curl_off_t ultotal, curl_off_t ulnow)
100100
{
101101
// Abort if callback isn't true
102-
return !impl->m_callback(dlnow, dltotal, ulnow, ultotal);
102+
return !impl->m_callback(static_cast<s64>(dltotal), static_cast<s64>(dlnow),
103+
static_cast<s64>(ultotal), static_cast<s64>(ulnow));
103104
}
104105

105106
HttpRequest::Impl::Impl(std::chrono::milliseconds timeout_ms, ProgressCallback callback)
@@ -116,7 +117,7 @@ HttpRequest::Impl::Impl(std::chrono::milliseconds timeout_ms, ProgressCallback c
116117
if (m_callback)
117118
{
118119
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSDATA, this);
119-
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSFUNCTION, CurlProgressCallback);
120+
curl_easy_setopt(m_curl.get(), CURLOPT_XFERINFOFUNCTION, CurlProgressCallback);
120121
}
121122

122123
// Set up error buffer

Source/Core/Common/HttpRequest.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class HttpRequest final
2525
};
2626

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

3130
explicit HttpRequest(std::chrono::milliseconds timeout_ms = std::chrono::milliseconds{3000},
3231
ProgressCallback callback = nullptr);

Source/Core/Common/SettingsHandler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ std::string SettingsHandler::GetValue(std::string_view key) const
7070

7171
void SettingsHandler::Decrypt()
7272
{
73-
const u8* str = m_buffer.data();
7473
while (m_position < m_buffer.size())
7574
{
7675
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
7776
m_position++;
78-
str++;
7977
m_key = (m_key >> 31) | (m_key << 1);
8078
}
8179

Source/Core/Core/FifoPlayer/FifoPlayer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <algorithm>
77
#include <cstring>
88
#include <mutex>
9+
#include <type_traits>
910

1011
#include "Common/Assert.h"
1112
#include "Common/CommonTypes.h"
@@ -101,14 +102,9 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file,
101102
part_start = offset;
102103
// Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after
103104
// primitive data, and the first opcode might update cpmem
104-
#ifdef __GNUC__
105-
#pragma GCC diagnostic push
106-
#pragma GCC diagnostic ignored "-Wclass-memaccess"
107-
#endif
108-
std::memcpy(&cpmem, &analyzer.m_cpmem, sizeof(CPState));
109-
#ifdef __GNUC__
110-
#pragma GCC diagnostic pop
111-
#endif
105+
static_assert(std::is_trivially_copyable_v<CPState>);
106+
std::memcpy(static_cast<void*>(&cpmem), static_cast<const void*>(&analyzer.m_cpmem),
107+
sizeof(CPState));
112108
}
113109
if (analyzer.m_end_of_primitives)
114110
{

Source/Core/Core/FifoPlayer/FifoRecorder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
268268
RecordInitialVideoMemory();
269269
}
270270

271-
auto& system = Core::System::GetInstance();
272-
auto& command_processor = system.GetCommandProcessor();
273-
const auto& fifo = command_processor.GetFifo();
271+
const auto& fifo = Core::System::GetInstance().GetCommandProcessor().GetFifo();
274272
EndFrame(fifo.CPBase.load(std::memory_order_relaxed),
275273
fifo.CPEnd.load(std::memory_order_relaxed));
276274
},

Source/Core/Core/HW/DSPHLE/UCodes/AESnd.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ constexpr u32 VOICE_16_BIT_FLAG = 2;
4444

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

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

5757
// These did not change between versions
5858
constexpr u32 VOICE_FINISHED = 0x00100000;
59-
constexpr u32 VOICE_STOPPED = 0x00200000; // not used by the DSP
59+
constexpr u32 VOICE_STOPPED [[maybe_unused]] = 0x00200000; // not used by the DSP
6060
constexpr u32 VOICE_RUNNING = 0x40000000;
61-
constexpr u32 VOICE_USED = 0x80000000; // not used by the DSP
61+
constexpr u32 VOICE_USED [[maybe_unused]] = 0x80000000; // not used by the DSP
6262

6363
// 1<<4 = scale gain by 1/1, 2<<2 = PCM decoding from ARAM, 1<<0 = 8-bit reads
6464
constexpr u32 ACCELERATOR_FORMAT_8_BIT = 0x0019;

Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
384384
if (size > 0)
385385
{
386386
// only if contain data
387-
if (static_cast<int>(this_seq - ref->ack_num) >= 0 && data.size() >= size)
387+
if (static_cast<int>(this_seq - ref->ack_num) >= 0 &&
388+
data.size() >= static_cast<size_t>(size))
388389
{
389390
ref->tcp_socket.send(data.data(), size);
390391
ref->ack_num += size;

0 commit comments

Comments
 (0)