diff --git a/rpcs3/Emu/Cell/Modules/cellDmux.cpp b/rpcs3/Emu/Cell/Modules/cellDmux.cpp index 42d2aaa6c9..4d33a37e6e 100644 --- a/rpcs3/Emu/Cell/Modules/cellDmux.cpp +++ b/rpcs3/Emu/Cell/Modules/cellDmux.cpp @@ -210,7 +210,7 @@ public: { DemuxerTask task; DemuxerStream stream = {}; - ElementaryStream* esALL[96]; memset(esALL, 0, sizeof(esALL)); + ElementaryStream* esALL[96]{}; ElementaryStream** esAVC = &esALL[0]; // AVC (max 16 minus M2V count) ElementaryStream** esM2V = &esALL[16]; // M2V (max 16 minus AVC count) ElementaryStream** esDATA = &esALL[32]; // user data (max 16) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 25261bd545..f9a4ac8f6b 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -229,7 +229,7 @@ static bool ds3_input_to_pad(const u32 port_no, be_t& digital_buttons, be_t } } - memset(&digital_buttons, 0, sizeof(digital_buttons)); + digital_buttons = 0; // map the Move key to R1 and the Trigger to R2 @@ -310,10 +310,10 @@ static bool mouse_input_to_pad(const u32 mouse_no, be_t& digital_buttons, b return false; } - memset(&digital_buttons, 0, sizeof(digital_buttons)); - const auto& mouse_data = handler->GetMice().at(0); + digital_buttons = 0; + if ((mouse_data.buttons & CELL_MOUSE_BUTTON_1) && (mouse_data.buttons & CELL_MOUSE_BUTTON_2)) digital_buttons |= CELL_GEM_CTRL_CIRCLE; if (mouse_data.buttons & CELL_MOUSE_BUTTON_3) diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index a86edb4eef..4483e974ac 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -251,6 +251,8 @@ error_code cellKbGetInfo(vm::ptr info) if (!info) return CELL_KB_ERROR_INVALID_PARAMETER; + std::memset(info.get_ptr(), 0, info.size()); + std::lock_guard lock(handler->m_mutex); const KbInfo& current_info = handler->GetInfo(); diff --git a/rpcs3/Emu/Cell/Modules/cellL10n.cpp b/rpcs3/Emu/Cell/Modules/cellL10n.cpp index 29c421e8ae..b6966cd9cf 100644 --- a/rpcs3/Emu/Cell/Modules/cellL10n.cpp +++ b/rpcs3/Emu/Cell/Modules/cellL10n.cpp @@ -285,7 +285,7 @@ s32 _ConvertStr(s32 src_code, const void *src, s32 src_len, s32 dst_code, void * s32 _L10nConvertStr(s32 src_code, vm::cptr src, vm::cptr src_len, s32 dst_code, vm::ptr dst, vm::ptr dst_len) { s32 dstLen = *dst_len; - s32 result = _ConvertStr(src_code, src.get_ptr(), *src_len, dst_code, dst == vm::null ? NULL : dst.get_ptr(), &dstLen, false); + s32 result = _ConvertStr(src_code, src.get_ptr(), *src_len, dst_code, dst ? dst.get_ptr() : nullptr, &dstLen, false); *dst_len = dstLen; return result; } @@ -413,7 +413,7 @@ s32 jstrnchk(vm::cptr src, s32 src_len) for (s32 len = 0; len < src_len; len++) { - if (src != vm::null) + if (src) { if (*src >= 0xa1 && *src <= 0xfe) { @@ -1274,7 +1274,7 @@ s32 UTF16stoUTF8s(vm::cptr utf16, vm::ref utf16_len, vm::ptr utf8, // return SRCIllegal; //} - if (utf8 != vm::null) + if (utf8) { if (len > max_len) { diff --git a/rpcs3/Emu/Cell/Modules/cellMouse.cpp b/rpcs3/Emu/Cell/Modules/cellMouse.cpp index d64f011117..3d320a7d05 100644 --- a/rpcs3/Emu/Cell/Modules/cellMouse.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMouse.cpp @@ -119,6 +119,8 @@ error_code cellMouseGetInfo(vm::ptr info) return CELL_MOUSE_ERROR_INVALID_PARAMETER; } + std::memset(info.get_ptr(), 0, info.size()); + const MouseInfo& current_info = handler->GetInfo(); info->max_connect = current_info.max_connect; info->now_connect = current_info.now_connect; @@ -192,13 +194,14 @@ error_code cellMouseGetData(u32 port_no, vm::ptr data) return CELL_MOUSE_ERROR_NO_DEVICE; } + std::memset(data.get_ptr(), 0, data.size()); + // TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact MouseDataList& data_list = handler->GetDataList(port_no); if (data_list.empty()) { - *data = {}; return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp b/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp index 72056a8407..e74f22f00c 100644 --- a/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp +++ b/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp @@ -113,7 +113,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr dia std::memset(osk->osk_text, 0, sizeof(osk->osk_text)); std::memset(osk->osk_text_old, 0, sizeof(osk->osk_text_old)); - if (inputFieldInfo->init_text.addr() != 0) + if (inputFieldInfo->init_text) { for (u32 i = 0; (i < maxLength) && (inputFieldInfo->init_text[i] != 0); i++) { @@ -124,10 +124,9 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr dia // Get message to display above the input field // Guarantees 0 terminated (+1). In praxis only 128 but for now lets display all of it - char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1]; - std::memset(message, 0, sizeof(message)); + char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1]{}; - if (inputFieldInfo->message.addr() != 0) + if (inputFieldInfo->message) { for (u32 i = 0; (i < CELL_OSKDIALOG_STRING_SIZE) && (inputFieldInfo->message[i] != 0); i++) { diff --git a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp index d75c896c22..18f3556d16 100644 --- a/rpcs3/Emu/Cell/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPngDec.cpp @@ -568,7 +568,7 @@ s32 pngDecSetParameter(PStream stream, PInParam in_param, POutParam out_param, P // This shouldnt ever happen, but not sure what to do if it does, just want it logged for now if (stream->info.bitDepth != 16 && in_param->outputBitDepth == 16) cellPngDec.error("Output depth of 16 with non input depth of 16 specified!"); - if (in_param->commandPtr != vm::null) + if (in_param->commandPtr) cellPngDec.warning("Ignoring CommandPtr."); if (stream->info.colorSpace != in_param->outputColorSpace) diff --git a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp index 012f9829d9..5b834d413f 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp @@ -3691,7 +3691,7 @@ s32 _cellSpursTasksetAttribute2Initialize(vm::ptr at { cellSpurs.warning("_cellSpursTasksetAttribute2Initialize(attribute=*0x%x, revision=%d)", attribute, revision); - memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute2)); + std::memset(attribute.get_ptr(), 0, attribute.size()); attribute->revision = revision; attribute->name = vm::null; attribute->args = 0; @@ -3960,11 +3960,11 @@ s32 _cellSpursTasksetAttributeInitialize(vm::ptr attr } } - memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute)); + std::memset(attribute.get_ptr(), 0, attribute.size()); attribute->revision = revision; attribute->sdk_version = sdk_version; attribute->args = args; - memcpy(attribute->priority, priority.get_ptr(), 8); + std::memcpy(attribute->priority, priority.get_ptr(), 8); attribute->taskset_size = 6400/*CellSpursTaskset::size*/; attribute->max_contention = max_contention; return CELL_OK; diff --git a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp index 12776d8031..ed6971b93d 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp @@ -903,16 +903,14 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus) spursSysServiceCleanupAfterSystemWorkload(spu, ctxt); // Trace - SERVICE: INIT - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE; pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_INIT; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); } // Trace - START: Module='SYS ' - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_START; memcpy(pkt.data.start.module, "SYS ", 4); pkt.data.start.level = 1; // Policy module @@ -928,14 +926,13 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus) if (cellSpursModulePollStatus(spu, nullptr)) { // Trace - SERVICE: EXIT - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE; pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_EXIT; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); // Trace - STOP: GUID - memset(&pkt, 0, sizeof(pkt)); + pkt = {}; pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP; pkt.data.stop = SPURS_GUID_SYS_WKL; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); @@ -956,8 +953,7 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus) // If we reach here it means that the SPU is idling // Trace - SERVICE: WAIT - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE; pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_WAIT; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); @@ -1287,8 +1283,7 @@ void spursSysServiceCleanupAfterSystemWorkload(spu_thread& spu, SpursKernelConte ctxt->wklCurrentId = wklId; // Trace - STOP: GUID - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP; pkt.data.stop = SPURS_GUID_SYS_WKL; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); @@ -1638,8 +1633,7 @@ void spursTasksetExit(spu_thread& spu) auto ctxt = vm::_ptr(spu.offset + 0x2700); // Trace - STOP - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = 0x54; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_STOP pkt.data.stop = SPURS_GUID_TASKSET_PM; cellSpursModulePutTrace(&pkt, ctxt->dmaTagId); @@ -1755,8 +1749,7 @@ void spursTasksetDispatch(spu_thread& spu) taskInfo->elf.set(taskInfo->elf.addr() & 0xFFFFFFFFFFFFFFF8); // Trace - Task: Incident=dispatch - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK; pkt.data.task.incident = CELL_SPURS_TRACE_TASK_DISPATCH; pkt.data.task.taskId = taskId; @@ -1791,7 +1784,7 @@ void spursTasksetDispatch(spu_thread& spu) } // Trace - GUID - memset(&pkt, 0, sizeof(pkt)); + pkt = {}; pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID; pkt.data.guid = 0; // TODO: Put GUID of taskId here cellSpursModulePutTrace(&pkt, 0x1F); @@ -1845,7 +1838,7 @@ void spursTasksetDispatch(spu_thread& spu) spu.set_ch_value(SPU_WrEventMask, ctxt->savedSpuWriteEventMask); // Trace - GUID - memset(&pkt, 0, sizeof(pkt)); + pkt = {}; pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID; pkt.data.guid = 0; // TODO: Put GUID of taskId here cellSpursModulePutTrace(&pkt, 0x1F); @@ -1949,8 +1942,7 @@ s32 spursTasksetProcessSyscall(spu_thread& spu, u32 syscallNum, u32 args) if (incident) { // Trace - TASK - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK; pkt.data.task.incident = incident; pkt.data.task.taskId = ctxt->taskId; @@ -1982,8 +1974,7 @@ void spursTasksetInit(spu_thread& spu, u32 pollStatus) kernelCtxt->moduleId[1] = 'K'; // Trace - START: Module='TKST' - CellSpursTracePacket pkt; - memset(&pkt, 0, sizeof(pkt)); + CellSpursTracePacket pkt{}; pkt.header.tag = 0x52; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_START memcpy(pkt.data.start.module, "TKST", 4); pkt.data.start.level = 2; diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index 6433c77657..1a53ab4541 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -458,7 +458,7 @@ error_code npDrmIsAvailable(vm::cptr k_licensee_addr, vm::cptr drm_pat if (magic == "SCE\0"_u32) { - if (k_licensee_addr == vm::null) + if (!k_licensee_addr) k_licensee = get_default_self_klic(); if (verify_npdrm_self_headers(enc_file, k_licensee.data())) diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 7d76a8a8e5..6b87e8ae39 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -588,9 +588,9 @@ error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptr n = trophy_base->GetChildren(); n; n = n->GetNext()) { @@ -691,19 +691,8 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt if (g_cfg.misc.show_trophy_popups) { - // Figure out how many zeros are needed for padding. (either 0, 1, or 2) - std::string padding = ""; - if (trophyId < 10) - { - padding = "00"; - } - else if (trophyId < 100) - { - padding = "0"; - } - // Get icon for the notification. - const std::string padded_trophy_id = padding + std::to_string(trophyId); + const std::string padded_trophy_id = fmt::format("%03u", trophyId); const std::string trophy_icon_path = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROP" + padded_trophy_id + ".PNG"; fs::file trophy_icon_file = fs::file(vfs::get(trophy_icon_path)); std::vector trophy_icon_data; @@ -823,9 +812,9 @@ error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::p } if (details) - memset(details.get_ptr(), 0, sizeof(SceNpTrophyDetails)); + *details = {}; if (data) - memset(data.get_ptr(), 0, sizeof(SceNpTrophyData)); + *data = {}; rXmlDocument doc; doc.Read(config.to_string()); diff --git a/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp b/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp index b740b88a38..9da2bea77e 100644 --- a/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp @@ -204,11 +204,11 @@ error_code sys_ppu_thread_register_atexit(ppu_thread& ppu, vm::ptr func) } } - for (auto& pp : *g_ppu_atexit) + for (auto& pf : *g_ppu_atexit) { - if (pp == vm::null) + if (!pf) { - pp = func; + pf = func; return CELL_OK; } } diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index dd2f4f4a17..40f980cf01 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -220,9 +220,7 @@ usb_handler_thread::~usb_handler_thread() void usb_handler_thread::operator()() { - timeval lusb_tv; - memset(&lusb_tv, 0, sizeof(timeval)); - lusb_tv.tv_usec = 200; + timeval lusb_tv{0, 200}; while (thread_ctrl::state() != thread_state::aborting) { diff --git a/rpcs3/Emu/Io/Null/NullKeyboardHandler.h b/rpcs3/Emu/Io/Null/NullKeyboardHandler.h index 56200e4308..51b4233074 100644 --- a/rpcs3/Emu/Io/Null/NullKeyboardHandler.h +++ b/rpcs3/Emu/Io/Null/NullKeyboardHandler.h @@ -7,7 +7,7 @@ class NullKeyboardHandler final : public KeyboardHandlerBase public: void Init(const u32 max_connect) override { - memset(&m_info, 0, sizeof(KbInfo)); + m_info = {}; m_info.max_connect = max_connect; m_keyboards.clear(); for (u32 i = 0; i < max_connect; i++) diff --git a/rpcs3/Emu/Io/Null/NullMouseHandler.h b/rpcs3/Emu/Io/Null/NullMouseHandler.h index ac05836318..e62a416679 100644 --- a/rpcs3/Emu/Io/Null/NullMouseHandler.h +++ b/rpcs3/Emu/Io/Null/NullMouseHandler.h @@ -7,7 +7,7 @@ class NullMouseHandler final : public MouseHandlerBase public: void Init(const u32 max_connect) override { - memset(&m_info, 0, sizeof(MouseInfo)); + m_info = {}; m_info.max_connect = max_connect; m_mice.clear(); } diff --git a/rpcs3/Emu/RSX/Common/texture_cache_checker.h b/rpcs3/Emu/RSX/Common/texture_cache_checker.h index 1030591c12..f08a7d38f6 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_checker.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_checker.h @@ -68,8 +68,11 @@ namespace rsx { // 4GB memory space / 4096 bytes per page = 1048576 pages + // Initialized to utils::protection::rw static constexpr size_t num_pages = 0x1'0000'0000 / 4096; - per_page_info_t _info[num_pages]; + per_page_info_t _info[num_pages]{0}; + + static_assert(static_cast(utils::protection::rw) == 0, "utils::protection::rw must have value 0 for the above constructor to work"); static constexpr size_t rsx_address_to_index(u32 address) { @@ -108,13 +111,6 @@ namespace rsx { } public: - tex_cache_checker_t() - { - // Initialize array to all 0 - memset(&_info, 0, sizeof(_info)); - } - static_assert(static_cast(utils::protection::rw) == 0, "utils::protection::rw must have value 0 for the above constructor to work"); - void set_protection(const address_range& range, utils::protection prot) { AUDIT(range.is_page_range()); diff --git a/rpcs3/Emu/RSX/GCM.h b/rpcs3/Emu/RSX/GCM.h index 77d44ceb2d..81d1629dad 100644 --- a/rpcs3/Emu/RSX/GCM.h +++ b/rpcs3/Emu/RSX/GCM.h @@ -111,12 +111,7 @@ struct GcmZcullInfo u32 sFunc; u32 sRef; u32 sMask; - bool binded; - - GcmZcullInfo() - { - memset(this, 0, sizeof(*this)); - } + bool binded = false; CellGcmZcullInfo pack() const { @@ -142,12 +137,7 @@ struct GcmTileInfo u32 comp; u32 base; u32 bank; - bool binded; - - GcmTileInfo() - { - memset(this, 0, sizeof(*this)); - } + bool binded = false; CellGcmTileInfo pack() const { diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index a61a8710cd..2ed38f3ccd 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -918,7 +918,7 @@ namespace rsx void thread::get_framebuffer_layout(rsx::framebuffer_creation_context context, framebuffer_layout &layout) { - memset(&layout, 0, sizeof(layout)); + layout = {}; layout.ignore_change = true; layout.width = rsx::method_registers.surface_clip_width(); diff --git a/rpcs3/Emu/RSX/rsx_methods.h b/rpcs3/Emu/RSX/rsx_methods.h index 80ebf8366f..c69a2b5ff1 100644 --- a/rpcs3/Emu/RSX/rsx_methods.h +++ b/rpcs3/Emu/RSX/rsx_methods.h @@ -543,7 +543,7 @@ namespace rsx vertex_arrays_info(fill_array(registers, std::make_index_sequence<16>())) { //NOTE: Transform constants persist through a context reset (NPEB00913) - memset(transform_constants.data(), 0, 512 * 4 * sizeof(u32)); + transform_constants = {}; } ~rsx_state() = default; diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index 070b9ccb8e..adfe0474ef 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -60,11 +60,7 @@ void pad_thread::Init() } } - const PadInfo pad_info(m_info); - std::memset(&m_info, 0, sizeof(m_info)); m_info.now_connect = 0; - m_info.system_info |= pad_info.system_info; - m_info.ignore_input = pad_info.ignore_input; handlers.clear();