From d57124d075566db9ff14fc3191c259bdb0e77b21 Mon Sep 17 00:00:00 2001 From: msuih Date: Fri, 28 Jun 2019 15:41:47 +0300 Subject: [PATCH] Explicitly cast size_t to integer types --- Utilities/File.cpp | 5 +++-- rpcs3/Emu/Cell/Modules/cellGem.cpp | 4 ++-- rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp | 10 +++++----- rpcs3/Emu/Cell/Modules/cellL10n.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellPngDec.cpp | 6 +++--- rpcs3/Emu/Cell/Modules/cellSaveData.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_prx.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_usbd.cpp | 2 +- rpcs3/Emu/RSX/CgBinaryProgram.h | 6 +++--- rpcs3/Loader/TAR.cpp | 2 +- rpcs3/basic_keyboard_handler.cpp | 2 +- rpcs3/basic_mouse_handler.cpp | 2 +- rpcs3/rpcs3qt/game_list_frame.cpp | 10 +++++----- 14 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index cff6d2932a..768626c1c4 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1460,8 +1460,9 @@ const std::string& fs::get_config_dir() #ifdef _WIN32 wchar_t buf[32768]; - if (GetEnvironmentVariable(L"RPCS3_CONFIG_DIR", buf, std::size(buf)) - 1 >= std::size(buf) - 1 && - GetModuleFileName(NULL, buf, std::size(buf)) - 1 >= std::size(buf) - 1) + constexpr DWORD size = static_cast(std::size(buf)); + if (GetEnvironmentVariable(L"RPCS3_CONFIG_DIR", buf, size) - 1 >= size - 1 && + GetModuleFileName(NULL, buf, size) - 1 >= size - 1) { MessageBoxA(0, fmt::format("GetModuleFileName() failed: error %u.", GetLastError()).c_str(), "fs::get_config_dir()", MB_ICONERROR); return dir; // empty diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 3427bfbbc2..c9eb77e8a1 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -442,7 +442,7 @@ s32 cellGemGetAllTrackableHues(vm::ptr hues) return CELL_GEM_ERROR_UNINITIALIZED; } - for (size_t i = 0; i < 360; i++) + for (u32 i = 0; i < 360; i++) { hues[i] = true; } @@ -960,7 +960,7 @@ s32 cellGemTrackHues(vm::cptr req_hues, vm::ptr res_hues) return CELL_GEM_ERROR_INVALID_PARAMETER; } - for (size_t i = 0; i < CELL_GEM_MAX_NUM; i++) + for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++) { if (req_hues[i] == CELL_GEM_DONT_CARE_HUE) { diff --git a/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp b/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp index 40d6383376..9dbd3e0448 100644 --- a/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp +++ b/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp @@ -26,11 +26,11 @@ s32 cellHttpUtilParseUri(vm::ptr uri, vm::cptr str, vm::ptr *dst_len) return DSTExhausted; memcpy(dst, target.c_str(), target.length()); } - *dst_len = target.length(); + *dst_len = ::narrow(target.size()); return ConversionOK; #else diff --git a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp index 41a187913e..d0a782a850 100644 --- a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp @@ -465,7 +465,7 @@ s32 pngDecOpen(ppu_thread& ppu, PHandle handle, PPStream png_stream, PSrc source } // We must indicate, that we allocated more memory - open_info->initSpaceAllocated += sizeof(PngBuffer); + open_info->initSpaceAllocated += u32{sizeof(PngBuffer)}; if (source->srcSelect == CELL_PNGDEC_BUFFER) { @@ -724,7 +724,7 @@ s32 pngDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr d stream->cbDispParam->nextOutputImage = disp_param->nextOutputImage; - streamInfo->decodedStrmSize = stream->buffer->cursor; + streamInfo->decodedStrmSize = ::narrow(stream->buffer->cursor); // push the rest of the buffer we have if (stream->buffer->length > stream->buffer->cursor) { @@ -738,7 +738,7 @@ s32 pngDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr d freeMem(); return CELL_PNGDEC_ERROR_FATAL; } - streamInfo->decodedStrmSize = stream->buffer->length; + streamInfo->decodedStrmSize = ::narrow(stream->buffer->length); } // todo: commandPtr diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index ca9982c0e5..54ec7efca0 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -451,7 +451,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v } case CELL_SAVEDATA_FOCUSPOS_LISTTAIL: { - focused = save_entries.size() - 1; + focused = ::size32(save_entries) - 1; break; } case CELL_SAVEDATA_FOCUSPOS_LATEST: @@ -512,7 +512,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v { if (!file.is_directory) { - doneGet->sizeKB += ::align(file.size, 4096); + doneGet->sizeKB += static_cast(::align(file.size, 4096)); if (!fs::remove_file(del_path + file.name)) { diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.cpp b/rpcs3/Emu/Cell/lv2/sys_prx.cpp index 092d5efcdf..1390a15bf2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_prx.cpp @@ -349,7 +349,7 @@ error_code _sys_prx_get_module_info(u32 id, u64 flags, vm::ptrinfo->modattribute = prx->module_info_attributes; pOpt->info->start_entry = prx->start.addr(); pOpt->info->stop_entry = prx->stop.addr(); - pOpt->info->all_segments_num = prx->segs.size(); + pOpt->info->all_segments_num = ::size32(prx->segs); if (pOpt->info->filename) { std::strncpy(pOpt->info->filename.get_ptr(), prx->name.c_str(), pOpt->info->filename_size); diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 667eec6c9c..ba68ba4f2c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -257,7 +257,7 @@ error_code sys_spu_thread_initialize(vm::ptr thread, u32 group_id, u32 spu_ if (++group->init == group->max_num) { - if (g_cfg.core.max_spurs_threads < 6 && group->max_num > g_cfg.core.max_spurs_threads) + if (g_cfg.core.max_spurs_threads < 6 && group->max_num > 0u + g_cfg.core.max_spurs_threads) { if (group->name.size() >= 20 && group->name.compare(group->name.size() - 20, 20, "CellSpursKernelGroup", 20) == 0) { diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index cc13ed230e..b5c3f688b0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -52,7 +52,7 @@ s32 sys_usbd_get_device_list(u32 handle, vm::ptr devi { device_list[i] = devices[i].basicDevice; } - return devices.size(); + return ::size32(devices); } s32 sys_usbd_register_extra_ldd(u32 handle, vm::ptr lddOps, u16 strLen, u16 vendorID, u16 productID, u16 unk1) diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index a54261f387..1458cf129b 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -308,7 +308,7 @@ public: m_arb_shader += fmt::format("#%d ", i) + param_type + param_name + param_semantic + param_const + "\n"; - offset += sizeof(CgBinaryParameter); + offset += u32{sizeof(CgBinaryParameter)}; } m_arb_shader += "\n"; @@ -324,7 +324,7 @@ public: size_t size = f.size(); vm::init(); - ptr = vm::alloc(size, vm::main); + ptr = vm::alloc(static_cast(size), vm::main); f.read(vm::base(ptr), size); } @@ -365,7 +365,7 @@ public: m_arb_shader += fmt::format("#%d ", i) + param_type + param_name + param_semantic + param_const + "\n"; - offset += sizeof(CgBinaryParameter); + offset += u32{sizeof(CgBinaryParameter)}; } m_arb_shader += "\n"; diff --git a/rpcs3/Loader/TAR.cpp b/rpcs3/Loader/TAR.cpp index c211aa71b1..065e131a63 100644 --- a/rpcs3/Loader/TAR.cpp +++ b/rpcs3/Loader/TAR.cpp @@ -7,7 +7,7 @@ tar_object::tar_object(const fs::file& file, size_t offset) : m_file(file) - , initial_offset(offset) + , initial_offset(static_cast(offset)) { m_file.seek(initial_offset); largest_offset = initial_offset; diff --git a/rpcs3/basic_keyboard_handler.cpp b/rpcs3/basic_keyboard_handler.cpp index d261ff2307..4fa5f8cdc1 100644 --- a/rpcs3/basic_keyboard_handler.cpp +++ b/rpcs3/basic_keyboard_handler.cpp @@ -22,7 +22,7 @@ void basic_keyboard_handler::Init(const u32 max_connect) LoadSettings(); memset(&m_info, 0, sizeof(KbInfo)); m_info.max_connect = max_connect; - m_info.now_connect = std::min(m_keyboards.size(), max_connect); + m_info.now_connect = std::min(::size32(m_keyboards), max_connect); m_info.info = 0; // Ownership of keyboard data: 0=Application, 1=System m_info.status[0] = CELL_KB_STATUS_CONNECTED; // (TODO: Support for more keyboards) } diff --git a/rpcs3/basic_mouse_handler.cpp b/rpcs3/basic_mouse_handler.cpp index 21aaf53c1a..6c235ba000 100644 --- a/rpcs3/basic_mouse_handler.cpp +++ b/rpcs3/basic_mouse_handler.cpp @@ -8,7 +8,7 @@ void basic_mouse_handler::Init(const u32 max_connect) m_mice.emplace_back(Mouse()); memset(&m_info, 0, sizeof(MouseInfo)); m_info.max_connect = max_connect; - m_info.now_connect = std::min(m_mice.size(), (size_t)max_connect); + m_info.now_connect = std::min(::size32(m_mice), max_connect); m_info.info = 0; // Ownership of mouse data: 0=Application, 1=System for (u32 i = 1; i < max_connect; i++) { diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index 5f03fb66e1..278bef4c41 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -1265,7 +1265,7 @@ void game_list_frame::BatchRemovePPUCaches() { serials.emplace(game->info.serial); } - const u32 total = serials.size(); + const u32 total = ::size32(serials); if (total == 0) { @@ -1307,7 +1307,7 @@ void game_list_frame::BatchRemoveSPUCaches() { serials.emplace(game->info.serial); } - const u32 total = serials.size(); + const u32 total = ::size32(serials); if (total == 0) { @@ -1352,7 +1352,7 @@ void game_list_frame::BatchRemoveCustomConfigurations() serials.emplace(game->info.serial); } } - const u32 total = serials.size(); + const u32 total = ::size32(serials); if (total == 0) { @@ -1398,7 +1398,7 @@ void game_list_frame::BatchRemoveCustomPadConfigurations() serials.emplace(game->info.serial); } } - const u32 total = serials.size(); + const u32 total = ::size32(serials); if (total == 0) { @@ -1441,7 +1441,7 @@ void game_list_frame::BatchRemoveShaderCaches() { serials.emplace(game->info.serial); } - const u32 total = serials.size(); + const u32 total = ::size32(serials); if (total == 0) {