From 632b74baf749c7c94378fbe8de6ba324ec9c764b Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 11 Jun 2024 23:59:40 +0200 Subject: [PATCH] vm_ptr: return nullptr and add some nullptr deref checks --- rpcs3/Emu/Memory/vm_ptr.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 3b0e910627cc..296c8f6bbe5f 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -101,23 +101,31 @@ namespace vm return vm::cast(m_addr); } + template T* get_ptr() const { + if constexpr (Strict) + { + AUDIT(mAddr); + } + return static_cast(vm::base(vm::cast(m_addr))); } T* operator ->() const requires (!std::is_void_v) { - return get_ptr(); + return get_ptr(); } std::add_lvalue_reference_t operator *() const requires (!std::is_void_v) { - return *static_cast(vm::base(vm::cast(m_addr))); + return *get_ptr(); } std::add_lvalue_reference_t operator [](u32 index) const requires (!std::is_void_v) { + AUDIT(mAddr); + return *static_cast(vm::base(vm::cast(m_addr) + u32{sizeof(T)} * index)); }