From 2edc3085a51a76fc2fc5219202a93dccba6a74a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 5 Jan 2025 22:49:17 +0100 Subject: [PATCH] PSPPointer<>: Replace some fiddly memsets with use of a new FillWithZero function. --- Core/HLE/sceNp.cpp | 10 +++++----- Core/MemMap.cpp | 4 +++- Core/MemMap.h | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index 540609c02b..76f9682ee1 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -158,7 +158,7 @@ static int sceNpGetOnlineId(u32 idPtr) if (!id.IsValid()) return hleLogError(Log::sceNet, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); - memset((SceNpOnlineId *)id, 0, sizeof(SceNpOnlineId)); + id.FillWithZero(); truncate_cpy(id->data, sizeof(id->data), npOnlineId.c_str()); id.NotifyWrite("NpGetOnlineId"); @@ -182,7 +182,7 @@ static int sceNpGetNpId(u32 idPtr) return hleLogError(Log::sceNet, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); SceNpId dummyNpId{}; - memset((SceNpId *)id, 0, sizeof(SceNpId)); + id.FillWithZero(); int retval = NpGetNpId(id); if (retval < 0) return hleLogError(Log::sceNet, retval); @@ -205,9 +205,9 @@ static int sceNpGetAccountRegion(u32 countryCodePtr, u32 regionCodePtr) if (!countryCode.IsValid() || !regionCode.IsValid()) return hleLogError(Log::sceNet, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); - memset((SceNpCountryCode *)countryCode, 0, sizeof(SceNpCountryCode)); + countryCode.FillWithZero(); memcpy(countryCode->data, npCountryCode, sizeof(countryCode->data)); - memset((SceNpCountryCode *)regionCode, 0, sizeof(SceNpCountryCode)); + regionCode.FillWithZero(); memcpy(regionCode->data, npRegionCode, sizeof(regionCode->data)); INFO_LOG(Log::sceNet, "%s - Country Code: %s", __FUNCTION__, countryCode->data); @@ -245,7 +245,7 @@ static int sceNpGetUserProfile(u32 profilePtr) if (!Memory::IsValidAddress(profilePtr)) return hleLogError(Log::sceNet, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); - memset((SceNpUserInformation *)profile, 0, sizeof(SceNpUserInformation)); + profile.FillWithZero(); truncate_cpy(profile->userId.handle.data, sizeof(profile->userId.handle.data), npOnlineId.c_str()); truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl.c_str()); diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 14b8e66d86..7b2bd955ab 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -497,7 +497,9 @@ void Memset(const u32 _Address, const u8 _iValue, const u32 _iLength, const char Write_U8(_iValue, (u32)(_Address + i)); } - NotifyMemInfo(MemBlockFlags::WRITE, _Address, _iLength, tag, strlen(tag)); + if (tag) { + NotifyMemInfo(MemBlockFlags::WRITE, _Address, _iLength, tag, strlen(tag)); + } } } // namespace diff --git a/Core/MemMap.h b/Core/MemMap.h index 03a77bc954..f802ead671 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -499,6 +499,10 @@ struct PSPPointer return Memory::IsValidRange(ptr, (u32)sizeof(T)); } + void FillWithZero() { + memset(Memory::GetPointerWrite(ptr), 0, sizeof(T)); + } + T *PtrOrNull() { if (IsValid()) return (T *)*this;