diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index 6b3b91d611..8b647537fb 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -923,7 +923,7 @@ public: name.append(".gz"); z_stream zs{}; - uLong zsz = compressBound(obj.getBufferSize()) + 256; + uLong zsz = compressBound(::narrow(obj.getBufferSize(), HERE)) + 256; auto zbuf = std::make_unique(zsz); #ifndef _MSC_VER #pragma GCC diagnostic push diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index 5df0cce332..9b6179c3c2 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -7,22 +7,13 @@ #include #include -// Copy null-terminated string from std::string to char array with truncation -template -inline void strcpy_trunc(char (&dst)[N], const std::string& src) +// Copy null-terminated string from a std::string or a char array to a char array with truncation +template +inline void strcpy_trunc(D& dst, const T& src) { - const std::size_t count = src.size() >= N ? N - 1 : src.size(); - std::memcpy(dst, src.c_str(), count); - std::memset(dst + count, 0, N - count); -} - -// Copy null-terminated string from char array to another char array with truncation -template -inline void strcpy_trunc(char (&dst)[N], const char (&src)[N2]) -{ - const std::size_t count = N2 >= N ? N - 1 : N2; - std::memcpy(dst, src, count); - std::memset(dst + count, 0, N - count); + const std::size_t count = std::size(src) >= std::size(dst) ? std::size(dst) - 1 : std::size(src); + std::memcpy(std::data(dst), std::data(src), count); + std::memset(std::data(dst) + count, 0, std::size(dst) - count); } namespace fmt diff --git a/Utilities/cond.cpp b/Utilities/cond.cpp index 53b88cf6d3..fc1981f6f1 100644 --- a/Utilities/cond.cpp +++ b/Utilities/cond.cpp @@ -1,4 +1,4 @@ -#include "cond.h" +#include "cond.h" #include "sync.h" #include "lockless.h" @@ -38,7 +38,7 @@ void cond_variable::imp_wake(u32 _count) noexcept } // Add signal - value += c_signal_mask & -c_signal_mask; + value += c_signal_mask & (0 - c_signal_mask); return true; }); @@ -47,7 +47,7 @@ void cond_variable::imp_wake(u32 _count) noexcept return; } - if (_count > 1 || ((_old + (c_signal_mask & -c_signal_mask)) & c_signal_mask) == c_signal_mask) + if (_count > 1 || ((_old + (c_signal_mask & (0 - c_signal_mask))) & c_signal_mask) == c_signal_mask) { // Resort to notify_all if signal count reached max m_value.notify_all(); diff --git a/rpcs3/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index 4397c45e2c..ac3303fc47 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "key_vault.h" #include "unedat.h" @@ -578,7 +578,7 @@ int validate_npd_hashes(const char* file_name, const u8* klicensee, NPD_HEADER * int title_hash_result = 0; int dev_hash_result = 0; - const auto file_name_length = std::strlen(file_name); + const s32 file_name_length = ::narrow(std::strlen(file_name), HERE); std::unique_ptr buf(new u8[0x30 + file_name_length]); // Build the title buffer (content_id + file_name). diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index f7e39a559f..7523e87c03 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -744,7 +744,7 @@ bool SCEDecrypter::DecryptData() // Calculate the total data size. for (unsigned int i = 0; i < meta_hdr.section_count; i++) { - data_buf_length += meta_shdr[i].data_size; + data_buf_length += ::narrow(meta_shdr[i].data_size, HERE); } // Allocate a buffer to store decrypted data. @@ -798,7 +798,7 @@ bool SCEDecrypter::DecryptData() } // Advance the buffer's offset. - data_buf_offset += meta_shdr[i].data_size; + data_buf_offset += ::narrow(meta_shdr[i].data_size, HERE); } return true; @@ -828,7 +828,7 @@ std::vector SCEDecrypter::MakeFile() strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; - strm.avail_in = meta_shdr[i].data_size; + strm.avail_in = ::narrow(meta_shdr[i].data_size, HERE); strm.avail_out = BUFSIZE; strm.next_in = data_buf.get()+data_buf_offset; strm.next_out = tempbuf; @@ -873,7 +873,7 @@ std::vector SCEDecrypter::MakeFile() } // Advance the data buffer offset by data size. - data_buf_offset += meta_shdr[i].data_size; + data_buf_offset += ::narrow(meta_shdr[i].data_size, HERE); if (out_f.pos() != out_f.size()) fmt::throw_exception("MakeELF written bytes (%llu) does not equal buffer size (%llu).", out_f.pos(), out_f.size()); @@ -1238,7 +1238,7 @@ bool SELFDecrypter::DecryptData() if (meta_shdr[i].encrypted == 3) { if ((meta_shdr[i].key_idx <= meta_hdr.key_count - 1) && (meta_shdr[i].iv_idx <= meta_hdr.key_count)) - data_buf_length += meta_shdr[i].data_size; + data_buf_length += ::narrow(meta_shdr[i].data_size, HERE); } } @@ -1284,7 +1284,7 @@ bool SELFDecrypter::DecryptData() memcpy(data_buf.get() + data_buf_offset, buf.get(), meta_shdr[i].data_size); // Advance the buffer's offset. - data_buf_offset += meta_shdr[i].data_size; + data_buf_offset += ::narrow(meta_shdr[i].data_size, HERE); } } } diff --git a/rpcs3/Crypto/unself.h b/rpcs3/Crypto/unself.h index 5bf77cd228..ae1d6354b3 100644 --- a/rpcs3/Crypto/unself.h +++ b/rpcs3/Crypto/unself.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "key_vault.h" #include "zlib.h" @@ -489,7 +489,7 @@ private: } // Advance the data buffer offset by data size. - data_buf_offset += meta_shdr[i].data_size; + data_buf_offset += ::narrow(meta_shdr[i].data_size, HERE); } } diff --git a/rpcs3/Crypto/utils.cpp b/rpcs3/Crypto/utils.cpp index 22f8de8ff3..c500391495 100644 --- a/rpcs3/Crypto/utils.cpp +++ b/rpcs3/Crypto/utils.cpp @@ -6,8 +6,12 @@ #include #include #include +#include "Utilities/StrUtil.h" +#include "Utilities/span.h" #include +#include +#include // Auxiliary functions (endian swap, xor). @@ -142,11 +146,9 @@ void cmac_hash_forge(unsigned char *key, int key_len, unsigned char *in, int in_ char* extract_file_name(const char* file_path, char real_file_name[MAX_PATH]) { - size_t file_path_len = strlen(file_path); - const char* p = strrchr(file_path, '/'); - if (!p) p = strrchr(file_path, '\\'); - if (p) file_path_len = file_path + file_path_len - p - 1; - strncpy(real_file_name, p ? (p + 1) : file_path, file_path_len + 1); - + std::string_view v(file_path); + v = v.substr(0, v.find_last_of("/\\")); + gsl::span r(real_file_name, MAX_PATH); + strcpy_trunc(r, v); return real_file_name; } diff --git a/rpcs3/Emu/CPU/CPUTranslator.cpp b/rpcs3/Emu/CPU/CPUTranslator.cpp index 8d0e088628..5d09f814eb 100644 --- a/rpcs3/Emu/CPU/CPUTranslator.cpp +++ b/rpcs3/Emu/CPU/CPUTranslator.cpp @@ -1,4 +1,4 @@ -#ifdef LLVM_AVAILABLE +#ifdef LLVM_AVAILABLE #include "CPUTranslator.h" @@ -117,21 +117,21 @@ v128 cpu_translator::get_const_vector(llvm::Constant* c, u32 a, u32 b) { for (u32 i = 0; i < 16; i++) { - result._u8[i] = cv->getElementAsInteger(i); + result._u8[i] = static_cast(cv->getElementAsInteger(i)); } } else if (sct->isIntegerTy(16)) { for (u32 i = 0; i < 8; i++) { - result._u16[i] = cv->getElementAsInteger(i); + result._u16[i] = static_cast(cv->getElementAsInteger(i)); } } else if (sct->isIntegerTy(32)) { for (u32 i = 0; i < 4; i++) { - result._u32[i] = cv->getElementAsInteger(i); + result._u32[i] = static_cast(cv->getElementAsInteger(i)); } } else if (sct->isIntegerTy(64)) diff --git a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp index f1292c68ce..6fe2e31101 100644 --- a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp +++ b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp @@ -80,7 +80,7 @@ bool statichle_handler::load_patterns() for (u32 j = 0; j < 32; j++) dapat.start_pattern[j] = char_to_u8(pattern[0][j * 2], pattern[0][(j * 2) + 1]); - dapat.crc16_length = char_to_u8(pattern[1][0], pattern[1][1]); + dapat.crc16_length = ::narrow(char_to_u8(pattern[1][0], pattern[1][1]), HERE); dapat.crc16 = (char_to_u8(pattern[2][0], pattern[2][1]) << 8) | char_to_u8(pattern[2][2], pattern[2][3]); dapat.total_length = (char_to_u8(pattern[3][0], pattern[3][1]) << 8) | char_to_u8(pattern[3][2], pattern[3][3]); dapat.module = pattern[4]; diff --git a/rpcs3/Emu/Cell/Modules/cellGame.cpp b/rpcs3/Emu/Cell/Modules/cellGame.cpp index 43bd286911..17826f78de 100644 --- a/rpcs3/Emu/Cell/Modules/cellGame.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGame.cpp @@ -10,6 +10,7 @@ #include "Loader/PSF.h" #include "Utilities/StrUtil.h" +#include "Utilities/span.h" #include "util/init_mutex.hpp" #include @@ -874,7 +875,6 @@ error_code cellGameGetParamString(s32 id, vm::ptr buf, u32 bufsize) } const std::string value = psf::get_string(prm->sfo, std::string(key.name)); - const auto value_size = value.size() + 1; if (value.empty() && !prm->sfo.count(std::string(key.name))) { @@ -882,15 +882,8 @@ error_code cellGameGetParamString(s32 id, vm::ptr buf, u32 bufsize) cellGame.warning("cellGameGetParamString(): id=%d was not found", id); } - const auto pbuf = buf.get_ptr(); - const bool to_pad = bufsize > value_size; - std::memcpy(pbuf, value.c_str(), to_pad ? value_size : bufsize); - - if (to_pad) - { - std::memset(pbuf + value_size, 0, bufsize - value_size); - } - + gsl::span dst(buf.get_ptr(), bufsize); + strcpy_trunc(dst, value); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellImeJp.cpp b/rpcs3/Emu/Cell/Modules/cellImeJp.cpp index afce196263..588d3a8aaf 100644 --- a/rpcs3/Emu/Cell/Modules/cellImeJp.cpp +++ b/rpcs3/Emu/Cell/Modules/cellImeJp.cpp @@ -56,7 +56,7 @@ bool ime_jp_manager::addString(vm::cptr str) if (!str) return false; - for (size_t i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) + for (u32 i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) { if (!addChar(str[i])) return false; @@ -111,7 +111,7 @@ void ime_jp_manager::moveCursorEnd(s8 amount) { if (amount > 0) { - cursor_end = std::max(static_cast(cursor), std::min(cursor_end + amount, input_string.length() - 1)); + cursor_end = std::max(static_cast(cursor), std::min(static_cast(cursor_end) + amount, ::narrow(input_string.length()) - 1)); } else if (amount < 0) { @@ -199,7 +199,7 @@ error_code cellImeJpOpen3(sys_memory_container_t container_id, vm::ptrpath[0]) { @@ -798,10 +798,10 @@ error_code cellImeJpMoveFocusClause(CellImeJpHandle hImeJpHandle, s16 moveType) manager->moveCursor(-1); break; case CELL_IMEJP_FOCUS_TOP: - manager->moveCursor((-1) * manager->input_string.length()); + manager->moveCursor(-1 * ::narrow(manager->input_string.length(), HERE)); break; case CELL_IMEJP_FOCUS_END: - manager->moveCursor(manager->input_string.length()); + manager->moveCursor(::narrow(manager->input_string.length(), HERE)); manager->moveCursor(-1); break; default: @@ -830,7 +830,7 @@ error_code cellImeJpGetFocusTop(CellImeJpHandle hImeJpHandle, vm::ptr pFocu return CELL_IMEJP_ERROR_CONTEXT; } - *pFocusTop = manager->cursor * 2; // offset in bytes + *pFocusTop = static_cast(manager->cursor * 2); // offset in bytes return CELL_OK; } @@ -858,7 +858,7 @@ error_code cellImeJpGetFocusLength(CellImeJpHandle hImeJpHandle, vm::ptr pF } else { - *pFocusLength = (manager->cursor_end - manager->cursor + 1) * 2; // offset in bytes + *pFocusLength = static_cast((manager->cursor_end - manager->cursor + 1) * 2); // offset in bytes } return CELL_OK; @@ -881,14 +881,14 @@ error_code cellImeJpGetConfirmYomiString(CellImeJpHandle hImeJpHandle, vm::ptr(CELL_IMEJP_STRING_MAXLENGTH - 1, manager->confirmed_string.length()); - for (size_t i = 0; i < max_len; i++) + for (u32 i = 0; i < max_len; i++) { pYomiString[i] = manager->confirmed_string[i]; } @@ -913,14 +913,14 @@ error_code cellImeJpGetConfirmString(CellImeJpHandle hImeJpHandle, vm::ptr return CELL_IMEJP_ERROR_CONTEXT; } - for (size_t i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) + for (u32 i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) { pConfirmString[i] = 0; } const size_t max_len = std::min(CELL_IMEJP_STRING_MAXLENGTH - 1, manager->confirmed_string.length()); - for (size_t i = 0; i < max_len; i++) + for (u32 i = 0; i < max_len; i++) { pConfirmString[i] = manager->confirmed_string[i]; } @@ -945,14 +945,14 @@ error_code cellImeJpGetConvertYomiString(CellImeJpHandle hImeJpHandle, vm::ptr(CELL_IMEJP_STRING_MAXLENGTH - 1, manager->input_string.length()); - for (size_t i = 0; i < max_len; i++) + for (u32 i = 0; i < max_len; i++) { pYomiString[i] = manager->input_string[i]; } @@ -977,14 +977,14 @@ error_code cellImeJpGetConvertString(CellImeJpHandle hImeJpHandle, vm::ptr return CELL_IMEJP_ERROR_CONTEXT; } - for (size_t i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) + for (u32 i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++) { pConvertString[i] = 0; } const size_t max_len = std::min(CELL_IMEJP_STRING_MAXLENGTH - 1, manager->input_string.length()); - for (size_t i = 0; i < max_len; i++) + for (u32 i = 0; i < max_len; i++) { pConvertString[i] = manager->input_string[i]; } diff --git a/rpcs3/Emu/Cell/Modules/cellSail.cpp b/rpcs3/Emu/Cell/Modules/cellSail.cpp index 62cac29200..31aee3a67a 100644 --- a/rpcs3/Emu/Cell/Modules/cellSail.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSail.cpp @@ -703,9 +703,9 @@ s32 cellSailPlayerSetParameter(vm::ptr pSelf, s32 parameterType, switch (parameterType) { - case CELL_SAIL_PARAMETER_GRAPHICS_ADAPTER_BUFFER_RELEASE_DELAY: pSelf->graphics_adapter_buffer_release_delay = param1; break; // TODO: Stream index - case CELL_SAIL_PARAMETER_CONTROL_PPU_THREAD_STACK_SIZE: pSelf->control_ppu_thread_stack_size = param0; break; - case CELL_SAIL_PARAMETER_ENABLE_APOST_SRC: pSelf->enable_apost_src = param1; break; // TODO: Stream index + case CELL_SAIL_PARAMETER_GRAPHICS_ADAPTER_BUFFER_RELEASE_DELAY: pSelf->graphics_adapter_buffer_release_delay = static_cast(param1); break; // TODO: Stream index + case CELL_SAIL_PARAMETER_CONTROL_PPU_THREAD_STACK_SIZE: pSelf->control_ppu_thread_stack_size = static_cast(param0); break; + case CELL_SAIL_PARAMETER_ENABLE_APOST_SRC: pSelf->enable_apost_src = static_cast(param1); break; // TODO: Stream index default: cellSail.todo("cellSailPlayerSetParameter(): unimplemented parameter %s", ParameterCodeToName(parameterType)); } @@ -718,6 +718,7 @@ s32 cellSailPlayerGetParameter(vm::ptr pSelf, s32 parameterType, switch (parameterType) { + case 0: default: cellSail.error("cellSailPlayerGetParameter(): unimplemented parameter %s", ParameterCodeToName(parameterType)); } @@ -806,7 +807,7 @@ s32 cellSailPlayerCreateDescriptor(vm::ptr pSelf, s32 streamType { if (fs::file f{ vfs::get(uri.substr(12)) }) { - u64 size = f.size(); + u32 size = ::size32(f); u32 buffer = vm::alloc(size, vm::main); auto bufPtr = vm::cptr::make(buffer); PamfHeader *buf = const_cast(bufPtr.get_ptr()); diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 67c43e3875..539acdf1f4 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -1767,7 +1767,7 @@ static NEVER_INLINE error_code savedata_get_list_item(vm::cptr dirName, vm } // get file stats, namely directory - strcpy_trunc(dir->dirName, dirName.get_ptr()); + strcpy_trunc(dir->dirName, std::string_view(dirName.get_ptr())); dir->atime = dir_info.atime; dir->ctime = dir_info.ctime; dir->mtime = dir_info.mtime; diff --git a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp index 79af78b067..b55324f68e 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp @@ -1047,8 +1047,7 @@ s32 _spurs::initialize(ppu_thread& ppu, vm::ptr spurs, u32 revision, // Create a thread group for this SPURS context std::memcpy(spuTgName.get_ptr(), spurs->prefix, spurs->prefixSize); - spuTgName[spurs->prefixSize] = '\0'; - std::strcat(spuTgName.get_ptr(), "CellSpursKernelGroup"); + std::memcpy(spuTgName.get_ptr() + spurs->prefixSize, "CellSpursKernelGroup", 21); spuTgAttr->name = spuTgName; spuTgAttr->nsize = static_cast(std::strlen(spuTgAttr->name.get_ptr())) + 1; @@ -1086,8 +1085,7 @@ s32 _spurs::initialize(ppu_thread& ppu, vm::ptr spurs, u32 revision, // Initialise all SPUs in the SPU thread group std::memcpy(spuThName.get_ptr(), spurs->prefix, spurs->prefixSize); - spuThName[spurs->prefixSize] = '\0'; - std::strcat(spuThName.get_ptr(), "CellSpursKernel"); + std::memcpy(spuThName.get_ptr() + spurs->prefixSize, "CellSpursKernel", 16); spuThAttr->name = spuThName; spuThAttr->name_len = static_cast(std::strlen(spuThName.get_ptr())) + 2; diff --git a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp index ae90d03a3d..477e5378ae 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp @@ -1207,7 +1207,7 @@ void spursSysServiceTraceUpdate(spu_thread& spu, SpursKernelContext* ctxt, u32 a } else { - std::memcpy(vm::base(spu.offset + 0x2C00), vm::base(spurs->traceBuffer.addr() & -0x4), 0x80); + std::memcpy(vm::base(spu.offset + 0x2C00), vm::base(vm::cast(spurs->traceBuffer.addr(), HERE) & -0x4), 0x80); auto traceBuffer = vm::_ptr(spu.offset + 0x2C00); ctxt->traceMsgCount = traceBuffer->count[ctxt->spuNum]; } @@ -1670,7 +1670,7 @@ s32 spursTasketSaveTaskContext(spu_thread& spu) return CELL_SPURS_TASK_ERROR_STAT; } - u32 allocLsBlocks = taskInfo->context_save_storage_and_alloc_ls_blocks & 0x7F; + u32 allocLsBlocks = static_cast(taskInfo->context_save_storage_and_alloc_ls_blocks & 0x7F); u32 lsBlocks = 0; v128 ls_pattern = v128::from64r(taskInfo->ls_pattern._u64[0], taskInfo->ls_pattern._u64[1]); for (auto i = 0; i < 128; i++) diff --git a/rpcs3/Emu/Cell/Modules/cellSync.cpp b/rpcs3/Emu/Cell/Modules/cellSync.cpp index 751fe25b8c..087952229c 100644 --- a/rpcs3/Emu/Cell/Modules/cellSync.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSync.cpp @@ -1091,7 +1091,7 @@ error_code _cellSyncLFQueueCompletePushPointer(ppu_thread& ppu, vm::ptrpush3.compare_and_swap_test(old2, push3)); verify(HERE), (fpSendSignal); - return not_an_error(fpSendSignal(ppu, queue->m_eaSignal.addr(), var6)); + return not_an_error(fpSendSignal(ppu, vm::cast(queue->m_eaSignal.addr(), HERE), var6)); } else { @@ -1390,7 +1390,7 @@ error_code _cellSyncLFQueueCompletePopPointer(ppu_thread& ppu, vm::ptrpop3.compare_and_swap_test(old2, pop3)); verify(HERE), (fpSendSignal); - return not_an_error(fpSendSignal(ppu, queue->m_eaSignal.addr(), var6)); + return not_an_error(fpSendSignal(ppu, vm::cast(queue->m_eaSignal.addr(), HERE), var6)); } else { diff --git a/rpcs3/Emu/Cell/Modules/cellSysutil.cpp b/rpcs3/Emu/Cell/Modules/cellSysutil.cpp index 35a7fd0a57..2a14cfedea 100644 --- a/rpcs3/Emu/Cell/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSysutil.cpp @@ -10,6 +10,7 @@ #include "Utilities/StrUtil.h" #include "Utilities/lockless.h" +#include "Utilities/span.h" LOG_CHANNEL(cellSysutil); @@ -348,8 +349,8 @@ error_code cellSysutilGetSystemParamString(CellSysutilParamId id, vm::ptr cellSysutil.error("cellSysutilGetSystemParamString: Unknown ParamId 0x%x", id); } - std::strncpy(buf.get_ptr(), param_str.c_str(), copy_size - 1); - buf[copy_size - 1] = '\0'; + gsl::span dst(buf.get_ptr(), copy_size); + strcpy_trunc(dst, param_str); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/sceNp2.h b/rpcs3/Emu/Cell/Modules/sceNp2.h index 37a20290be..87009370fd 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp2.h +++ b/rpcs3/Emu/Cell/Modules/sceNp2.h @@ -6,8 +6,6 @@ #include -extern logs::channel sceNp2; - // Error codes enum SceNpMatching2Error : u32 { diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 5bcc7ddf04..d5cea91bf8 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -861,7 +861,7 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt const std::string& config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM"); const u32 unlocked_platinum_id = ctxt->tropusr->GetUnlockedPlatinumID(trophyId, config_path); - if (unlocked_platinum_id != 0u + SCE_NP_TROPHY_INVALID_TROPHY_ID) + if (unlocked_platinum_id != SCE_NP_TROPHY_INVALID_TROPHY_ID) { sceNpTrophy.warning("sceNpTrophyUnlockTrophy: All requirements for unlocking the platinum trophy (ID = %d) were met.)", unlocked_platinum_id); @@ -885,7 +885,7 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt // Enqueue popup for the regular trophy show_trophy_notification(ctxt, trophyId); - if (unlocked_platinum_id != 0u + SCE_NP_TROPHY_INVALID_TROPHY_ID) + if (unlocked_platinum_id != SCE_NP_TROPHY_INVALID_TROPHY_ID) { // Enqueue popup for the holy platinum trophy show_trophy_notification(ctxt, unlocked_platinum_id); diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.h b/rpcs3/Emu/Cell/Modules/sceNpTrophy.h index e7b33c54f2..35e9d46e1c 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.h +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.h @@ -65,7 +65,11 @@ enum SCE_NP_TROPHY_INVALID_CONTEXT = 0, SCE_NP_TROPHY_INVALID_HANDLE = 0, - SCE_NP_TROPHY_INVALID_TROPHY_ID = -1, +}; + +enum : u32 +{ + SCE_NP_TROPHY_INVALID_TROPHY_ID = 0xffffffff, }; enum SceNpTrophyGrade diff --git a/rpcs3/Emu/Cell/Modules/sys_mempool.cpp b/rpcs3/Emu/Cell/Modules/sys_mempool.cpp index bddad6fe72..1fe5cfaf0b 100644 --- a/rpcs3/Emu/Cell/Modules/sys_mempool.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_mempool.cpp @@ -71,7 +71,7 @@ s32 sys_mempool_create(ppu_thread& ppu, vm::ptr mempool, vm::ptr< memory_pool->free_blocks.resize(num_blocks); for (u32 i = 0; i < num_blocks; ++i) { - memory_pool->free_blocks[i] = vm::ptr::make(chunk.addr() + i * block_size); + memory_pool->free_blocks[i] = vm::ptr::make(chunk.addr() + i * static_cast(block_size)); } // Create synchronization variables diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index 7ca5ed354e..4129cca798 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -1210,7 +1210,7 @@ bool ppu_interpreter_fast::VMSUMSHS(ppu_thread& ppu, ppu_opcode_t op) { saturated = 0x7fffffff; } - else if (result < -0x80000000) + else if (result < INT32_MIN) { saturated = 0x80000000; } @@ -1246,7 +1246,7 @@ bool ppu_interpreter_precise::VMSUMSHS(ppu_thread& ppu, ppu_opcode_t op) saturated = 0x7fffffff; ppu.sat = true; } - else if (result < -0x80000000) + else if (result < INT32_MIN) { saturated = 0x80000000; ppu.sat = true; @@ -2929,7 +2929,7 @@ bool ppu_interpreter::BC(ppu_thread& ppu, ppu_opcode_t op) if (op.lk) ppu.lr = ppu.cia + 4; const bool ctr_ok = bo2 | ((ppu.ctr != 0) ^ bo3); - const bool cond_ok = bo0 | (ppu.cr[op.bi] ^ (bo1 ^ true)); + const bool cond_ok = bo0 | (!!(ppu.cr[op.bi]) ^ (bo1 ^ true)); if (ctr_ok && cond_ok) { @@ -2978,7 +2978,7 @@ bool ppu_interpreter::BCLR(ppu_thread& ppu, ppu_opcode_t op) ppu.ctr -= (bo2 ^ true); const bool ctr_ok = bo2 | ((ppu.ctr != 0) ^ bo3); - const bool cond_ok = bo0 | (ppu.cr[op.bi] ^ (bo1 ^ true)); + const bool cond_ok = bo0 | (!!(ppu.cr[op.bi]) ^ (bo1 ^ true)); const u32 target = static_cast(ppu.lr) & ~3; if (op.lk) ppu.lr = ppu.cia + 4; @@ -4368,7 +4368,7 @@ bool ppu_interpreter::EXTSB(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STFIWX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::write32(vm::cast(addr, HERE), std::bit_cast(ppu.fpr[op.frs])); + vm::write32(vm::cast(addr, HERE), static_cast(std::bit_cast(ppu.fpr[op.frs]))); return true; } @@ -4431,7 +4431,7 @@ bool ppu_interpreter::STW(ppu_thread& ppu, ppu_opcode_t op) //Insomniac engine v3 & v4 (newer R&C, Fuse, Resitance 3) if (value == 0xAAAAAAAA) [[unlikely]] { - vm::reservation_update(addr, 128); + vm::reservation_update(vm::cast(addr, HERE), 128); } return true; diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 4eeb224e63..09eb24e405 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -811,7 +811,7 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri _sec.addr = addr - saddr + prx->segs[i].addr; _sec.size = size; _sec.type = s.sh_type; - _sec.flags = s.sh_flags & 7; + _sec.flags = static_cast(s.sh_flags & 7); _sec.filesz = 0; prx->secs.emplace_back(_sec); break; @@ -1121,7 +1121,7 @@ void ppu_load_exec(const ppu_exec_object& elf) const u32 addr = _sec.addr = vm::cast(s.sh_addr); const u32 size = _sec.size = vm::cast(s.sh_size); const u32 type = _sec.type = s.sh_type; - const u32 flag = _sec.flags = s.sh_flags & 7; + const u32 flag = _sec.flags = static_cast(s.sh_flags & 7); _sec.filesz = 0; if (s.sh_type == 1u && addr && size) @@ -1691,7 +1691,7 @@ std::shared_ptr ppu_load_overlay(const ppu_exec_object& elf, const const u32 addr = _sec.addr = vm::cast(s.sh_addr); const u32 size = _sec.size = vm::cast(s.sh_size); const u32 type = _sec.type = s.sh_type; - const u32 flag = _sec.flags = s.sh_flags & 7; + const u32 flag = _sec.flags = static_cast(s.sh_flags & 7); _sec.filesz = 0; if (s.sh_type == 1u && addr && size) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index d8e7ce326e..a516c4a9a0 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -910,7 +910,7 @@ void ppu_thread::stack_pop_verbose(u32 addr, u32 size) noexcept return; } - context.gpr[1] = vm::_ref>(context.gpr[1] + size); + context.gpr[1] = vm::_ref>(static_cast(context.gpr[1]) + size); return; } diff --git a/rpcs3/Emu/Cell/PPUTranslator.cpp b/rpcs3/Emu/Cell/PPUTranslator.cpp index 3e4df3c63b..f7fbd4d2d8 100644 --- a/rpcs3/Emu/Cell/PPUTranslator.cpp +++ b/rpcs3/Emu/Cell/PPUTranslator.cpp @@ -231,7 +231,7 @@ Type* PPUTranslator::ScaleType(Type* type, s32 pow2) { verify(HERE), (type->getScalarType()->isIntegerTy()); - const auto new_type = m_ir->getIntNTy(type->getScalarSizeInBits() * std::pow(2, pow2)); + const auto new_type = m_ir->getIntNTy(type->getScalarSizeInBits() * (1 << pow2)); return type->isVectorTy() ? VectorType::get(new_type, type->getVectorNumElements()) : cast(new_type); } @@ -270,7 +270,7 @@ void PPUTranslator::CallFunction(u64 target, Value* indirect) } else { - m_ir->CreateStore(Trunc(indirect, GetType()), m_ir->CreateStructGEP(nullptr, m_thread, &m_cia - m_locals), true); + m_ir->CreateStore(Trunc(indirect, GetType()), m_ir->CreateStructGEP(nullptr, m_thread, static_cast(&m_cia - m_locals)), true); // Try to optimize if (auto inst = dyn_cast_or_null(indirect)) @@ -357,7 +357,7 @@ void PPUTranslator::FlushRegisters() Value* PPUTranslator::Solid(Value* value) { - const u32 size = value->getType()->getPrimitiveSizeInBits(); + const u32 size = ::narrow(+value->getType()->getPrimitiveSizeInBits(), HERE); /* Workarounds (casting bool vectors directly may produce invalid code) */ @@ -531,7 +531,7 @@ llvm::Value* PPUTranslator::GetMemory(llvm::Value* addr, llvm::Type* type) Value* PPUTranslator::ReadMemory(Value* addr, Type* type, bool is_be, u32 align) { - const auto size = type->getPrimitiveSizeInBits(); + const u32 size = ::narrow(+type->getPrimitiveSizeInBits(), HERE); if (is_be ^ m_is_be && size > 8) { @@ -548,7 +548,7 @@ Value* PPUTranslator::ReadMemory(Value* addr, Type* type, bool is_be, u32 align) void PPUTranslator::WriteMemory(Value* addr, Value* value, bool is_be, u32 align) { const auto type = value->getType(); - const auto size = type->getPrimitiveSizeInBits(); + const u32 size = ::narrow(+type->getPrimitiveSizeInBits(), HERE); if (is_be ^ m_is_be && size > 8) { @@ -1758,7 +1758,7 @@ void PPUTranslator::BC(ppu_opcode_t op) if (op.lk) { - m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, &m_lr - m_locals)); + m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast(&m_lr - m_locals))); } UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi)); @@ -1828,7 +1828,7 @@ void PPUTranslator::BCLR(ppu_opcode_t op) if (op.lk) { - m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, &m_lr - m_locals)); + m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast(&m_lr - m_locals))); } UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi)); @@ -1891,7 +1891,7 @@ void PPUTranslator::BCCTR(ppu_opcode_t op) if (op.lk) { - m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, &m_lr - m_locals)); + m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast(&m_lr - m_locals))); } UseCondition(CheckBranchProbability(op.bo | 0x4), CheckBranchCondition(op.bo | 0x4, op.bi)); @@ -2613,7 +2613,7 @@ void PPUTranslator::MTOCRF(ppu_opcode_t op) const auto index = m_ir->CreateAnd(m_ir->CreateLShr(value, 28 - i * 4), 15); const auto src = m_ir->CreateGEP(m_mtocr_table, {m_ir->getInt32(0), m_ir->CreateShl(index, 2)}); - const auto dst = m_ir->CreateBitCast(m_ir->CreateStructGEP(nullptr, m_thread, m_cr - m_locals + i * 4), GetType()); + const auto dst = m_ir->CreateBitCast(m_ir->CreateStructGEP(nullptr, m_thread, static_cast(m_cr - m_locals) + i * 4), GetType()); Call(GetType(), "llvm.memcpy.p0i8.p0i8.i32", dst, src, m_ir->getInt32(4), m_ir->getFalse()); } } diff --git a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp index 856ec2ad65..f76f6d928c 100644 --- a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp @@ -3844,7 +3844,7 @@ void spu_recompiler::CGX(spu_opcode_t op) //nf c->paddd(res, vb); } - c->movdqa(sign, XmmConst(_mm_set1_epi32(-0x80000000))); + c->movdqa(sign, XmmConst(_mm_set1_epi32(INT32_MIN))); c->pxor(va, sign); c->pxor(res, sign); c->pcmpgtd(va, res); @@ -3877,7 +3877,7 @@ void spu_recompiler::BGX(spu_opcode_t op) //nf } c->pand(vt, temp); - c->movdqa(sign, XmmConst(_mm_set1_epi32(-0x80000000))); + c->movdqa(sign, XmmConst(_mm_set1_epi32(INT32_MIN))); c->pxor(va, sign); c->pxor(vb, sign); c->pcmpgtd(vb, va); @@ -4779,11 +4779,11 @@ void spu_recompiler::SHUFB(spu_opcode_t op) const XmmLink& vt = XmmAlloc(); const XmmLink& vm = XmmAlloc(); const XmmLink& v5 = XmmAlloc(); - c->movdqa(vm, XmmConst(_mm_set1_epi8(0xc0))); + c->movdqa(vm, XmmConst(_mm_set1_epi8(static_cast(0xc0)))); if (utils::has_avx()) { - c->vpand(v5, vc, XmmConst(_mm_set1_epi8(0xe0))); + c->vpand(v5, vc, XmmConst(_mm_set1_epi8(static_cast(0xe0)))); c->vpxor(vc, vc, XmmConst(_mm_set1_epi8(0xf))); c->vpshufb(va, va, vc); c->vpslld(vt, vc, 3); @@ -4798,7 +4798,7 @@ void spu_recompiler::SHUFB(spu_opcode_t op) else { c->movdqa(v5, vc); - c->pand(v5, XmmConst(_mm_set1_epi8(0xe0))); + c->pand(v5, XmmConst(_mm_set1_epi8(static_cast(0xe0)))); c->movdqa(vt, vc); c->pand(vt, vm); c->pxor(vc, XmmConst(_mm_set1_epi8(0xf))); diff --git a/rpcs3/Emu/Cell/SPUInterpreter.cpp b/rpcs3/Emu/Cell/SPUInterpreter.cpp index 7004a5ab63..24efde89e7 100644 --- a/rpcs3/Emu/Cell/SPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/SPUInterpreter.cpp @@ -1705,8 +1705,8 @@ static bool SHUFB_(spu_thread& spu, spu_opcode_t op) } // Select special values - const auto xc0 = _mm_set1_epi8(0xc0); - const auto xe0 = _mm_set1_epi8(0xe0); + const auto xc0 = _mm_set1_epi8(static_cast(0xc0)); + const auto xe0 = _mm_set1_epi8(static_cast(0xe0)); const auto cmp0 = _mm_cmpgt_epi8(_mm_setzero_si128(), c.vi); const auto cmp1 = _mm_cmpeq_epi8(_mm_and_si128(c.vi, xc0), xc0); const auto cmp2 = _mm_cmpeq_epi8(_mm_and_si128(c.vi, xe0), xc0); diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index cacfe08309..2d5c481533 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -425,7 +425,7 @@ void spu_cache::initialize() } g_progr = "Building SPU cache..."; - g_progr_ptotal += func_list.size(); + g_progr_ptotal += ::size32(func_list); } named_thread_group workers("SPU Worker ", Emu.GetMaxThreads(), [&]() -> uint @@ -1498,7 +1498,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) if (jt_abs.size() >= jt_rel.size()) { - const u32 new_size = (start - lsa) / 4 + jt_abs.size(); + const u32 new_size = (start - lsa) / 4 + ::size32(jt_abs); if (result.data.size() < new_size) { @@ -1517,7 +1517,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) if (jt_rel.size() >= jt_abs.size()) { - const u32 new_size = (start - lsa) / 4 + jt_rel.size(); + const u32 new_size = (start - lsa) / 4 + ::size32(jt_rel); if (result.data.size() < new_size) { @@ -1869,7 +1869,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) { m_regmod[pos / 4] = op.rt; - if (-op.i7 & 0x20) + if ((0 - op.i7) & 0x20) { vflags[op.rt] = +vf::is_const; values[op.rt] = 0; @@ -1877,7 +1877,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) } vflags[op.rt] = vflags[op.ra] & vf::is_const; - values[op.rt] = values[op.ra] >> (-op.i7 & 0x1f); + values[op.rt] = values[op.ra] >> ((0 - op.i7) & 0x1f); break; } case spu_itype::SHLI: @@ -1930,7 +1930,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) while (lsa > 0 || limit < 0x40000) { - const u32 initial_size = result.data.size(); + const u32 initial_size = ::size32(result.data); // Check unreachable blocks limit = std::min(limit, lsa + initial_size * 4); diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 0735ca7829..a78780aee7 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -12,8 +12,8 @@ LOG_CHANNEL(sys_fs); struct lv2_fs_mount_point { - const u64 sector_size = 512; - const u64 block_size = 4096; + const u32 sector_size = 512; + const u32 block_size = 4096; const bs_t flags{}; shared_mutex mutex; diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index c45ded0f78..d124c608b0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -80,6 +80,14 @@ void fmt_class_string::format(std::string& out, u64 arg) }); } +template <> +void fmt_class_string::format(std::string& out, u64 arg) +{ + const uchar* data = reinterpret_cast(&get_object(arg)); + + fmt::append(out, "%u.%u.%u.%u", data[0], data[1], data[2], data[3]); +} + #ifdef _WIN32 // Workaround function for WSAPoll not reporting failed connections void windows_poll(pollfd* fds, unsigned long nfds, int timeout, bool* connecting) @@ -244,7 +252,7 @@ struct network_thread { // Wait with 1ms timeout #ifdef _WIN32 - windows_poll(fds, socklist.size(), 1, connecting); + windows_poll(fds, ::size32(socklist), 1, connecting); #else ::poll(fds, socklist.size(), 1); #endif @@ -515,12 +523,12 @@ error_code sys_net_bnet_bind(ppu_thread& ppu, s32 s, vm::cptr { const u16 daport = reinterpret_cast(addr.get_ptr())->sin_port; const u16 davport = reinterpret_cast(addr.get_ptr())->sin_vport; - sys_net.warning("Trying to bind %s:%d:%d", inet_ntoa(name.sin_addr), daport, davport); + sys_net.warning("Trying to bind %s:%d:%d", name.sin_addr, daport, davport); name.sin_port = std::bit_cast>(daport + davport); // htons(daport + davport) } else { - sys_net.warning("Trying to bind %s:%d", inet_ntoa(name.sin_addr), std::bit_cast, u16>(name.sin_port)); // ntohs(name.sin_port) + sys_net.warning("Trying to bind %s:%d", name.sin_addr, std::bit_cast, u16>(name.sin_port)); // ntohs(name.sin_port) } std::lock_guard lock(sock.mutex); @@ -561,7 +569,7 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr(psa_in->sin_addr); ::socklen_t namelen = sizeof(name); - sys_net.warning("Attempting to connect on %s:%d", inet_ntoa(name.sin_addr), std::bit_cast, u16>(name.sin_port)); // ntohs(name.sin_port) + sys_net.warning("Attempting to connect on %s:%d", name.sin_addr, std::bit_cast, u16>(name.sin_port)); // ntohs(name.sin_port) const auto sock = idm::check(s, [&](lv2_socket& sock) { @@ -745,9 +753,9 @@ error_code sys_net_bnet_getpeername(ppu_thread& ppu, s32 s, vm::ptr paddr_p2p = vm::cast(addr.addr()); paddr_p2p->sin_vport = paddr_p2p->sin_port - 3658; paddr_p2p->sin_port = 3658; - in_addr rep; + struct in_addr rep; rep.s_addr = htonl(paddr->sin_addr); - sys_net.error("Reporting P2P socket address as %s:%d:%d", inet_ntoa(rep), paddr_p2p->sin_port, paddr_p2p->sin_vport); + sys_net.error("Reporting P2P socket address as %s:%d:%d", rep, paddr_p2p->sin_port, paddr_p2p->sin_vport); } return {}; @@ -1230,14 +1238,14 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 const u16 daport = reinterpret_cast(addr.get_ptr())->sin_port; const u16 davport = reinterpret_cast(addr.get_ptr())->sin_vport; - sys_net.error("Received a P2P packet from %s:%d:%d", inet_ntoa(reinterpret_cast<::sockaddr_in*>(&native_addr)->sin_addr), daport, davport); + sys_net.error("Received a P2P packet from %s:%d:%d", reinterpret_cast<::sockaddr_in*>(&native_addr)->sin_addr, daport, davport); } } // Length if (type == SYS_NET_SOCK_DGRAM_P2P) sys_net.error("Ok recvfrom: %d", native_result); - + return not_an_error(native_result); } @@ -1309,7 +1317,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l { const u16 daport = reinterpret_cast(addr.get_ptr())->sin_port; const u16 davport = reinterpret_cast(addr.get_ptr())->sin_vport; - sys_net.error("Sending a P2P packet to %s:%d:%d", inet_ntoa(name.sin_addr), daport, davport); + sys_net.error("Sending a P2P packet to %s:%d:%d", name.sin_addr, daport, davport); name.sin_port = std::bit_cast>(daport + davport); // htons(daport + davport) } @@ -1416,7 +1424,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l // Length if (type == SYS_NET_SOCK_DGRAM_P2P) sys_net.error("Ok sendto: %d", native_result); - + return not_an_error(native_result); } diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.cpp b/rpcs3/Emu/Cell/lv2/sys_prx.cpp index 38466c1d34..d281395bbf 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_prx.cpp @@ -8,11 +8,11 @@ #include "Emu/Cell/ErrorCodes.h" #include "Crypto/unedat.h" +#include "Utilities/StrUtil.h" +#include "Utilities/span.h" #include "sys_fs.h" #include "sys_process.h" - - extern std::shared_ptr ppu_load_prx(const ppu_prx_object&, const std::string&); extern void ppu_unload_prx(const lv2_prx& prx); extern void ppu_initialize(const ppu_module&); @@ -395,7 +395,8 @@ error_code _sys_prx_get_module_info(u32 id, u64 flags, vm::ptrinfo->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); + gsl::span dst(pOpt->info->filename.get_ptr(), pOpt->info->filename_size); + strcpy_trunc(dst, prx->name); pOpt->info->filename[pOpt->info->filename_size - 1] = 0; } diff --git a/rpcs3/Emu/Cell/lv2/sys_rsx.cpp b/rpcs3/Emu/Cell/lv2/sys_rsx.cpp index d800dc727b..27cf8e3094 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsx.cpp @@ -144,7 +144,7 @@ error_code sys_rsx_context_allocate(vm::ptr context_id, vm::ptr lpar_d *lpar_driver_info = context_base + 0x100000; *lpar_reports = context_base + 0x200000; - auto &reports = vm::_ref(*lpar_reports); + auto &reports = vm::_ref(vm::cast(*lpar_reports, HERE)); std::memset(&reports, 0, sizeof(RsxReports)); for (int i = 0; i < 64; ++i) @@ -164,7 +164,7 @@ error_code sys_rsx_context_allocate(vm::ptr context_id, vm::ptr lpar_d reports.report[i].pad = -1; } - auto &driverInfo = vm::_ref(*lpar_driver_info); + auto &driverInfo = vm::_ref(vm::cast(*lpar_driver_info, HERE)); std::memset(&driverInfo, 0, sizeof(RsxDriverInfo)); @@ -176,12 +176,12 @@ error_code sys_rsx_context_allocate(vm::ptr context_id, vm::ptr lpar_d driverInfo.reportsNotifyOffset = 0x1000; driverInfo.reportsOffset = 0; driverInfo.reportsReportOffset = 0x1400; - driverInfo.systemModeFlags = system_mode; + driverInfo.systemModeFlags = static_cast(system_mode); driverInfo.hardware_channel = 1; // * i think* this 1 for games, 0 for vsh - rsx_cfg->driver_info = *lpar_driver_info; + rsx_cfg->driver_info = vm::cast(*lpar_driver_info, HERE); - auto &dmaControl = vm::_ref(*lpar_dma_control); + auto &dmaControl = vm::_ref(vm::cast(*lpar_dma_control, HERE)); dmaControl.get = 0; dmaControl.put = 0; dmaControl.ref = 0; // Set later to -1 by cellGcmSys @@ -204,10 +204,10 @@ error_code sys_rsx_context_allocate(vm::ptr context_id, vm::ptr lpar_d const auto render = rsx::get_current_renderer(); render->display_buffers_count = 0; render->current_display_buffer = 0; - render->label_addr = *lpar_reports; + render->label_addr = vm::cast(*lpar_reports, HERE); render->device_addr = rsx_cfg->device_addr; render->local_mem_size = rsx_cfg->memory_size; - render->init(*lpar_dma_control); + render->init(vm::cast(*lpar_dma_control, HERE)); rsx_cfg->context_base = context_base; *context_id = 0x55555555; @@ -350,9 +350,9 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 { case 0x001: // FIFO render->pause(); - render->ctrl->get = a3; - render->ctrl->put = a4; - render->restore_point = a3; + render->ctrl->get = static_cast(a3); + render->ctrl->put = static_cast(a4); + render->restore_point = static_cast(a3); render->unpause(); break; @@ -408,7 +408,7 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 case 0x103: // Display Queue { - driverInfo.head[a3].lastQueuedBufferId = a4; + driverInfo.head[a3].lastQueuedBufferId = static_cast(a4); driverInfo.head[a3].flipFlags |= 0x40000000 | (1 << a4); // NOTE: There currently seem to only be 2 active heads on PS3 @@ -417,7 +417,7 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 const u64 shift_offset = (a3 + 5); sys_event_port_send(rsx_cfg->rsx_event_port, 0, (1ull << shift_offset), 0); - render->on_frame_end(a4); + render->on_frame_end(static_cast(a4)); } break; @@ -465,7 +465,7 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 } u32 flipStatus = driverInfo.head[a3].flipFlags; - flipStatus = (flipStatus & a4) | a5; + flipStatus = (flipStatus & static_cast(a4)) | static_cast(a5); driverInfo.head[a3].flipFlags = flipStatus; } break; @@ -485,7 +485,7 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 // When tile is going to be unbinded, we can use it as a hint that the address will no longer be used as a surface and can be removed/invalidated // Todo: There may be more checks such as format/size/width can could be done if (tile.binded && a5 == 0) - render->notify_tile_unbound(a3); + render->notify_tile_unbound(static_cast(a3)); tile.location = ((a4 >> 32) & 0xF) - 1; tile.offset = ((((a4 >> 32) & 0x7FFFFFFF) >> 16) * 0x10000); @@ -569,7 +569,7 @@ error_code sys_rsx_context_attribute(u32 context_id, u32 package_id, u64 a3, u64 // 'custom' invalid package id for now // as i think we need custom lv1 interrupts to handle this accurately // this also should probly be set by rsxthread - driverInfo.userCmdParam = a4; + driverInfo.userCmdParam = static_cast(a4); sys_event_port_send(rsx_cfg->rsx_event_port, 0, (1 << 7), 0); break; @@ -610,7 +610,8 @@ error_code sys_rsx_device_map(vm::ptr dev_addr, vm::ptr a2, u32 dev_id return CELL_ENOMEM; } - rsx_cfg->device_addr = *dev_addr = addr; + *dev_addr = addr; + rsx_cfg->device_addr = addr; return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_ss.cpp b/rpcs3/Emu/Cell/lv2/sys_ss.cpp index e5407d67ad..86fab523a8 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ss.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ss.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "sys_ss.h" #include "sys_process.h" @@ -59,7 +59,7 @@ error_code sys_ss_random_number_generator(u64 pkg_id, vm::ptr buf, u64 siz std::unique_ptr temp(new u8[size]); #ifdef _WIN32 - if (auto ret = BCryptGenRandom(nullptr, temp.get(), size, BCRYPT_USE_SYSTEM_PREFERRED_RNG)) + if (auto ret = BCryptGenRandom(nullptr, temp.get(), static_cast(size), BCRYPT_USE_SYSTEM_PREFERRED_RNG)) { fmt::throw_exception("sys_ss_random_number_generator(): BCryptGenRandom failed (0x%08x)" HERE, ret); } diff --git a/rpcs3/Emu/GDB.cpp b/rpcs3/Emu/GDB.cpp index b896a1321d..650c1aace9 100644 --- a/rpcs3/Emu/GDB.cpp +++ b/rpcs3/Emu/GDB.cpp @@ -141,7 +141,7 @@ void gdb_thread::start_server() if (getaddrinfo(bind_addr.c_str(), bind_port.c_str(), &hints, &info) == 0) { - server_socket = socket(info->ai_family, info->ai_socktype, info->ai_protocol); + server_socket = static_cast(socket(info->ai_family, info->ai_socktype, info->ai_protocol)); if (server_socket == -1) { @@ -173,7 +173,7 @@ void gdb_thread::start_server() } // Fallback to UNIX socket - server_socket = socket(AF_UNIX, SOCK_STREAM, 0); + server_socket = static_cast(socket(AF_UNIX, SOCK_STREAM, 0)); if (server_socket == -1) { @@ -848,7 +848,7 @@ void gdb_thread::operator()() { sockaddr_in client; socklen_t client_len = sizeof(client); - client_socket = accept(server_socket, reinterpret_cast(&client), &client_len); + client_socket = static_cast(accept(server_socket, reinterpret_cast(&client), &client_len)); if (client_socket == -1) { diff --git a/rpcs3/Emu/Io/GHLtar.cpp b/rpcs3/Emu/Io/GHLtar.cpp index 99dc9f1f37..ee3031b200 100644 --- a/rpcs3/Emu/Io/GHLtar.cpp +++ b/rpcs3/Emu/Io/GHLtar.cpp @@ -199,7 +199,7 @@ void usb_device_ghltar::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, pad->m_analog_right_x = stick.m_value; break; case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X: - buf[19] = stick.m_value; // Tilt + buf[19] = static_cast(stick.m_value); // Tilt if (buf[19] >= 0xF0) buf[5] = 0xFF; if (buf[19] <= 0x10) diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index e625953a67..917ca191ac 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -20,9 +20,9 @@ #include #endif -extern logs::channel sys_net; -extern logs::channel sceNp2; -extern logs::channel sceNp; +LOG_CHANNEL(sys_net); +LOG_CHANNEL(sceNp2); +LOG_CHANNEL(sceNp); np_handler::np_handler() { @@ -35,17 +35,16 @@ np_handler::np_handler() // cur_ip = g_cfg.net.ip_address; // Attempt to get actual IP address - const char* google_dns_server = "8.8.8.8"; const int dns_port = 53; struct sockaddr_in serv; - const int sock = socket(AF_INET, SOCK_DGRAM, 0); + const int sock = static_cast(socket(AF_INET, SOCK_DGRAM, 0)); ASSERT(sock >= 0); memset(&serv, 0, sizeof(serv)); serv.sin_family = AF_INET; - serv.sin_addr.s_addr = inet_addr(google_dns_server); + serv.sin_addr.s_addr = 0x08'08'08'08; // 8.8.8.8 google_dns_server serv.sin_port = std::bit_cast>(dns_port); // htons(dns_port) int err = connect(sock, reinterpret_cast(&serv), sizeof(serv)); @@ -137,7 +136,7 @@ void np_handler::init_NP(u32 poolsize, vm::ptr poolptr) std::string s_npid = g_cfg.net.psn_npid; ASSERT(s_npid != ""); // It should be generated in settings window if empty - strncpy(npid.handle.data, s_npid.c_str(), sizeof(npid.handle.data)); + strcpy_trunc(npid.handle.data, s_npid); } switch (g_cfg.net.psn_status) @@ -146,8 +145,8 @@ void np_handler::init_NP(u32 poolsize, vm::ptr poolptr) break; case np_psn_status::fake: { - strncpy(online_name.data, "RPCS3's user", sizeof(online_name.data)); - strncpy(avatar_url.data, "https://i.imgur.com/AfWIyQP.jpg", sizeof(avatar_url.data)); + strcpy_trunc(online_name.data, "RPCS3's user"); + strcpy_trunc(avatar_url.data, "https://i.imgur.com/AfWIyQP.jpg"); break; } default: diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 4294fe9235..a31a6b3411 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -604,7 +604,7 @@ namespace auto src_stream = static_cast(src); auto dst_stream = static_cast<__m128i*>(dst); - __m128i min = _mm_set1_epi16(0xFFFF); + __m128i min = _mm_set1_epi16(-1); __m128i max = _mm_set1_epi16(0); const auto iterations = count / 8; @@ -671,7 +671,7 @@ namespace { T min_index, max_index; u32 written; - u32 remaining = src.size(); + u32 remaining = ::size32(src, HERE); if (s_use_sse4_1 && remaining >= 32) { @@ -729,7 +729,7 @@ namespace auto dst_stream = static_cast<__m256i*>(dst); __m256i restart = _mm256_set1_epi16(restart_index); - __m256i min = _mm256_set1_epi16(0xffff); + __m256i min = _mm256_set1_epi16(-1); __m256i max = _mm256_set1_epi16(0); for (unsigned n = 0; n < iterations; ++n) @@ -772,7 +772,7 @@ namespace auto dst_stream = static_cast<__m128i*>(dst); __m128i restart = _mm_set1_epi16(restart_index); - __m128i min = _mm_set1_epi16(0xffff); + __m128i min = _mm_set1_epi16(-1); __m128i max = _mm_set1_epi16(0); for (unsigned n = 0; n < iterations; ++n) @@ -845,7 +845,7 @@ namespace T min_index = index_limit(); T max_index = 0; u32 written = 0; - u32 length = src.size(); + u32 length = ::size32(src, HERE); if (length >= 32 && !skip_restart) { diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp b/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp index 5a157cacd7..235f57bd1c 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp @@ -424,7 +424,7 @@ size_t fragment_program_storage_hash::operator()(const RSXFragmentProgram& progr hash ^= program.ctrl; hash ^= program.texture_dimensions; hash ^= program.unnormalized_coords; - hash ^= program.two_sided_lighting; + hash ^= +program.two_sided_lighting; hash ^= program.shadow_textures; hash ^= program.redirected_textures; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_animation.cpp b/rpcs3/Emu/RSX/Overlays/overlay_animation.cpp index f44e0bea55..eac0e427c5 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_animation.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_animation.cpp @@ -31,10 +31,10 @@ namespace rsx t = t * t; break; case animation_type::ease_out_quad: - t = t * (2.0 - t); + t = t * (2.0f - t); break; case animation_type::ease_in_out_cubic: - t = t > 0.5 ? 4.0 * std::pow((t - 1.0), 3.0) + 1.0 : 4.0 * std::pow(t, 3.0); + t = t > 0.5f ? 4.0f * std::pow((t - 1.0f), 3.0f) + 1.0f : 4.0f * std::pow(t, 3.0f); break; } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.h b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.h index fed0175269..a6e8c58465 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.h @@ -7,9 +7,8 @@ namespace rsx { namespace overlays { - struct message_dialog : public user_interface + class message_dialog : public user_interface { - private: label text_display; image_button btn_ok; image_button btn_cancel; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp index 645e202f4a..6c221fc3ad 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp @@ -494,7 +494,7 @@ namespace rsx void osk_dialog::on_mode(const std::u32string&) { - const u32 num_modes = std::clamp(num_layers.size(), 1, layer_mode::mode_count); + const u32 num_modes = std::clamp(::size32(num_layers), 1, layer_mode::mode_count); m_selected_mode = static_cast((m_selected_mode + 1u) % num_modes); m_update = true; } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp index 3d19b136e8..8f9a911212 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp @@ -218,7 +218,7 @@ namespace rsx if (enabled) { m_fps_graph.set_title(" Framerate"); - m_fps_graph.set_font_size(m_font_size * 0.8); + m_fps_graph.set_font_size(static_cast(m_font_size * 0.8)); m_fps_graph.set_count(50); m_fps_graph.set_color(convert_color_code(m_color_body, m_opacity)); m_fps_graph.set_guide_interval(10); @@ -237,7 +237,7 @@ namespace rsx if (enabled) { m_frametime_graph.set_title(" Frametime"); - m_frametime_graph.set_font_size(m_font_size * 0.8); + m_frametime_graph.set_font_size(static_cast(m_font_size * 0.8)); m_frametime_graph.set_count(170); m_frametime_graph.set_color(convert_color_code(m_color_body, m_opacity)); m_frametime_graph.set_guide_interval(8); @@ -351,7 +351,7 @@ namespace rsx if (m_frametime_graph_enabled) { const auto elapsed_frame = m_frametime_timer.GetElapsedTimeInMilliSec(); - m_frametime_graph.record_datapoint(elapsed_frame); + m_frametime_graph.record_datapoint(static_cast(elapsed_frame)); } if (m_force_repaint) @@ -400,7 +400,7 @@ namespace rsx { case detail_level::high: { - frametime = m_force_update ? 0 : std::max(0.0, elapsed_update / m_frames); + frametime = m_force_update ? 0.f : std::max(0.f, static_cast(elapsed_update / m_frames)); rsx_load = rsx_thread->get_load(); @@ -423,7 +423,7 @@ namespace rsx rsx_cycles += rsx_thread->get_cycles(); total_cycles = std::max(1, ppu_cycles + spu_cycles + rsx_cycles); - cpu_usage = m_cpu_stats.get_usage(); + cpu_usage = static_cast(m_cpu_stats.get_usage()); ppu_usage = std::clamp(cpu_usage * ppu_cycles / total_cycles, 0.f, 100.f); spu_usage = std::clamp(cpu_usage * spu_cycles / total_cycles, 0.f, 100.f); @@ -434,13 +434,13 @@ namespace rsx case detail_level::low: { if (cpu_usage < 0.) - cpu_usage = m_cpu_stats.get_usage(); + cpu_usage = static_cast(m_cpu_stats.get_usage()); // fallthrough } case detail_level::minimal: { - fps = m_force_update ? 0 : std::max(0.0, static_cast(m_frames) / (elapsed_update / 1000)); + fps = m_force_update ? 0.f : std::max(0.f, static_cast(m_frames / (elapsed_update / 1000))); if (m_is_initialised && m_framerate_graph_enabled) m_fps_graph.record_datapoint(fps); } @@ -655,7 +655,7 @@ namespace rsx { const f32 guide_y = y + y_off * normalize_factor; verts_guides.emplace_back(x, guide_y); - verts_guides.emplace_back(x + w, guide_y); + verts_guides.emplace_back(static_cast(x + w), guide_y); } } @@ -667,10 +667,10 @@ namespace rsx auto& verts_graph = compiled_resources.draw_commands.back().verts; - const f32 x_stride = f32(w) / m_datapoint_count; - const u32 tail_index_offset = m_datapoints.size() - m_datapoint_count; + const f32 x_stride = w * 1.f / m_datapoint_count; + const u32 tail_index_offset = ::size32(m_datapoints, HERE) - m_datapoint_count; - for (size_t i = 0; i < m_datapoint_count; ++i) + for (u32 i = 0; i < m_datapoint_count; ++i) { const f32 x_line = x + i * x_stride; const f32 y_line = y + h - (m_datapoints[tail_index_offset + i] * normalize_factor); diff --git a/rpcs3/Emu/RSX/rsx_methods.cpp b/rpcs3/Emu/RSX/rsx_methods.cpp index 7674e5d586..de68adac81 100644 --- a/rpcs3/Emu/RSX/rsx_methods.cpp +++ b/rpcs3/Emu/RSX/rsx_methods.cpp @@ -1130,7 +1130,7 @@ namespace rsx convert_w != out_w || convert_h != out_h; const bool need_convert = out_format != in_format || !rsx::fcmp(fabsf(scale_x), 1.f) || !rsx::fcmp(fabsf(scale_y), 1.f); - const u32 slice_h = std::ceil(f32(clip_h + clip_y) / scale_y); + const u32 slice_h = static_cast(std::ceil(static_cast(clip_h + clip_y) / scale_y)); if (method_registers.blit_engine_context_surface() != blit_engine::context_surface::swizzle2d) { diff --git a/rpcs3/Loader/TAR.cpp b/rpcs3/Loader/TAR.cpp index a5f7e63f87..58874919b6 100644 --- a/rpcs3/Loader/TAR.cpp +++ b/rpcs3/Loader/TAR.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "TAR.h" @@ -30,7 +30,7 @@ int octalToDecimal(int octalNumber) { rem = octalNumber % 10; octalNumber /= 10; - decimalNumber += rem * pow(8, i); + decimalNumber += rem * (1 << (i * 3)); ++i; } return decimalNumber; diff --git a/rpcs3/Loader/TRP.cpp b/rpcs3/Loader/TRP.cpp index a7cf64f170..02dc8c2302 100644 --- a/rpcs3/Loader/TRP.cpp +++ b/rpcs3/Loader/TRP.cpp @@ -148,7 +148,7 @@ void TRPLoader::RenameEntry(const char *oldname, const char *newname) { if (!strcmp(entry.name, oldname)) { - strcpy_trunc(entry.name, newname); + strcpy_trunc(entry.name, std::string_view(newname)); } } } diff --git a/rpcs3/rpcs3qt/memory_string_searcher.cpp b/rpcs3/rpcs3qt/memory_string_searcher.cpp index 99a8a126b1..28e56d2899 100644 --- a/rpcs3/rpcs3qt/memory_string_searcher.cpp +++ b/rpcs3/rpcs3qt/memory_string_searcher.cpp @@ -36,7 +36,7 @@ void memory_string_searcher::OnSearch() { const std::string wstr = m_addr_line->text().toStdString(); const char *str = wstr.c_str(); - const u32 len = wstr.length(); + const u32 len = ::size32(wstr); gui_log.notice("Searching for string %s", str); diff --git a/rpcs3/util/atomic.cpp b/rpcs3/util/atomic.cpp index 5bc1a8a815..f0f8fdee74 100644 --- a/rpcs3/util/atomic.cpp +++ b/rpcs3/util/atomic.cpp @@ -269,7 +269,7 @@ static u32 sema_alloc() if (ok) { // Find lowest clear bit - const u32 id = group * 64 + utils::cnttz64(~bits, false); + const u32 id = group * 64 + static_cast(utils::cnttz64(~bits, false)); #ifdef USE_POSIX // Initialize semaphore (should be very fast) diff --git a/rpcs3/util/atomic2.cpp b/rpcs3/util/atomic2.cpp index 1218502f2c..af3a8297dd 100644 --- a/rpcs3/util/atomic2.cpp +++ b/rpcs3/util/atomic2.cpp @@ -244,7 +244,7 @@ static constexpr u64 s_ref_one = s_state_mask + 1; static u64 rec_alloc() { - const u32 start = __rdtsc(); + const u32 start = static_cast(__rdtsc()); for (u32 i = 0;; i++) {