From 90b6f5613e0ccc2ae50018aa659e5ea0b462e80e Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:56:52 +0200 Subject: [PATCH] Fix some warnings --- rpcs3/Crypto/unedat.cpp | 4 ++-- rpcs3/Crypto/utils.cpp | 12 ++++++------ rpcs3/Crypto/utils.h | 12 ++++++------ rpcs3/Emu/Cell/PPUModule.cpp | 16 ++++++++-------- rpcs3/util/types.hpp | 13 ++++++++++++- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/rpcs3/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index 5ffec82fd8..e8a3b3cff5 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -509,7 +509,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: // Setup signature hash. if ((edat->flags & EDAT_FLAG_0x20) != 0) //Sony failed again, they used buffer from 0x100 with half size of real metadata. { - int metadata_buf_size = block_num * 0x10; + const usz metadata_buf_size = block_num * 0x10; std::unique_ptr metadata_buf(new u8[metadata_buf_size]); f->seek(file_offset + metadata_offset); f->read(metadata_buf.get(), metadata_buf_size); @@ -941,7 +941,7 @@ bool EDATADecrypter::ReadHeader() }*/ file_size = edatHeader.file_size; - total_blocks = utils::aligned_div(edatHeader.file_size, edatHeader.block_size); + total_blocks = ::narrow(utils::aligned_div(edatHeader.file_size, edatHeader.block_size)); // Try decrypting the first block instead u8 data_sample[1]; diff --git a/rpcs3/Crypto/utils.cpp b/rpcs3/Crypto/utils.cpp index 19e0b3d2ab..1858fb1fa0 100644 --- a/rpcs3/Crypto/utils.cpp +++ b/rpcs3/Crypto/utils.cpp @@ -66,7 +66,7 @@ void hex_to_bytes(unsigned char* data, const char* hex_str, unsigned int str_len // Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC). -void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, int len) +void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len) { aes_context ctx; aes_setkey_dec(&ctx, key, 128); @@ -76,7 +76,7 @@ void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, memset(iv, 0, 0x10); } -void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, int len) +void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len) { aes_context ctx; aes_setkey_enc(&ctx, key, 128); @@ -93,7 +93,7 @@ void aesecb128_encrypt(unsigned char *key, unsigned char *in, unsigned char *out aes_crypt_ecb(&ctx, AES_ENCRYPT, in, out); } -bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash, int hash_len) +bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len) { const std::unique_ptr out(new u8[key_len]); @@ -102,12 +102,12 @@ bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int i return std::memcmp(out.get(), hash, hash_len) == 0; } -void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash) +void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash) { sha1_hmac(key, key_len, in, in_len, hash); } -bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash, int hash_len) +bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len) { const std::unique_ptr out(new u8[key_len]); @@ -118,7 +118,7 @@ bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int i return std::memcmp(out.get(), hash, hash_len) == 0; } -void cmac_hash_forge(unsigned char *key, int /*key_len*/, unsigned char *in, int in_len, unsigned char *hash) +void cmac_hash_forge(unsigned char *key, int /*key_len*/, unsigned char *in, usz in_len, unsigned char *hash) { aes_context ctx; aes_setkey_enc(&ctx, key, 128); diff --git a/rpcs3/Crypto/utils.h b/rpcs3/Crypto/utils.h index 3e36989dfe..b7e4634f06 100644 --- a/rpcs3/Crypto/utils.h +++ b/rpcs3/Crypto/utils.h @@ -20,13 +20,13 @@ u64 hex_to_u64(const char* hex_str); void hex_to_bytes(unsigned char *data, const char *hex_str, unsigned int str_length); // Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC). -void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, int len); -void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, int len); +void aescbc128_decrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len); +void aescbc128_encrypt(unsigned char *key, unsigned char *iv, unsigned char *in, unsigned char *out, usz len); void aesecb128_encrypt(unsigned char *key, unsigned char *in, unsigned char *out); -bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash, int hash_len); -void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash); -bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash, int hash_len); -void cmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, int in_len, unsigned char *hash); +bool hmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len); +void hmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash); +bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash, usz hash_len); +void cmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, usz in_len, unsigned char *hash); void mbedtls_zeroize(void *v, size_t n); // SC passphrase crypto diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 7d01594c0e..64caf51f4e 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -370,7 +370,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link, utils::serial* ar = n auto& variable = _module->variables; - for (u32 i = 0, end = ar.pop(); i < end; i++) + for (usz i = 0, end = ar.pop(); i < end; i++) { auto* ptr = &::at32(variable, ar.pop()); ptr->addr = ar.pop(); @@ -973,7 +973,7 @@ void ppu_manual_load_imports_exports(u32 imports_start, u32 imports_size, u32 ex auto& link = g_fxo->get(); ppu_module vm_all_fake_module{}; - vm_all_fake_module.segs.emplace_back(ppu_segment{0x10000, -0x10000u, 1 /*LOAD*/, 0, -0x1000u, vm::base(0x10000)}); + vm_all_fake_module.segs.emplace_back(ppu_segment{0x10000, 0 - 0x10000u, 1 /*LOAD*/, 0, 0 - 0x1000u, vm::base(0x10000)}); vm_all_fake_module.addr_to_seg_index.emplace(0x10000, 0); ppu_load_exports(vm_all_fake_module, &link, exports_start, exports_start + exports_size, false, &loaded_flags); @@ -1084,13 +1084,13 @@ static void ppu_check_patch_spu_images(const ppu_module& mod, const ppu_segment& auto find_first_of_multiple = [](std::string_view data, std::initializer_list values, usz index) { - usz pos = umax; + u32 pos = static_cast(data.size()); for (std::string_view value : values) { if (usz pos0 = data.substr(index, pos - index).find(value); pos0 != umax && pos0 + index < pos) { - pos = pos0 + index; + pos = static_cast(pos0 + index); } } @@ -1102,9 +1102,9 @@ static void ppu_check_patch_spu_images(const ppu_module& mod, const ppu_segment& // Search for [stqd lr,0x10(sp)] instruction or ELF file signature, whichever comes first const std::initializer_list prefixes = {"\177ELF"sv, "\x24\0\x40\x80"sv}; - usz prev_bound = 0; + u32 prev_bound = 0; - for (usz i = find_first_of_multiple(seg_view, prefixes, 0); i < seg.size; i = find_first_of_multiple(seg_view, prefixes, utils::align(i + 1, 4))) + for (u32 i = find_first_of_multiple(seg_view, prefixes, 0); i < seg.size; i = find_first_of_multiple(seg_view, prefixes, utils::align(i + 1, 4))) { const auto elf_header = ensure(mod.get_ptr(seg.addr + i)); @@ -1358,7 +1358,7 @@ static void ppu_check_patch_spu_images(const ppu_module& mod, const ppu_segment& ppu_loader.success("SPU executable hash: %s (<- %u)%s", hash, applied.size(), dump); } - i += obj.highest_offset - 4; + i += ::narrow(obj.highest_offset) - 4; prev_bound = i + 4; } } @@ -1424,7 +1424,7 @@ struct prx_names_table // Doesn't support addresses above 256MB because it wastes memory and is very unlikely (if somehow does occur increase it) const u32 max0 = (seg.addr + seg.size - 1) >> 16; - const u32 max = std::min(std::size(lut), max0); + const u32 max = std::min(::size32(lut), max0); if (max0 > max) { diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index 6a155a8991..8194962566 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -1045,7 +1045,18 @@ template requires requires (const CT& x) { std::size(x); } const char* file = __builtin_FILE(), const char* func = __builtin_FUNCTION()) { - return narrow(std::size(container), line, col, file, func); + // TODO: Supoort std::array + constexpr bool is_const = std::is_array_v>; + + if constexpr (is_const) + { + constexpr usz Size = sizeof(container) / sizeof(container[0]); + return std::conditional_t{Size}; + } + else + { + return narrow(std::size(container), line, col, file, func); + } } template requires requires (CT&& x) { std::size(x); std::data(x); } || requires (CT&& x) { std::size(x); x.front(); }