Skip to content

Commit

Permalink
vm_ptr: return nullptr and add some nullptr deref checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jun 11, 2024
1 parent 1e5cd7f commit 632b74b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rpcs3/Emu/Memory/vm_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,31 @@ namespace vm
return vm::cast(m_addr);
}

template <bool Strict = false>
T* get_ptr() const
{
if constexpr (Strict)
{
AUDIT(mAddr);
}

return static_cast<T*>(vm::base(vm::cast(m_addr)));
}

T* operator ->() const requires (!std::is_void_v<T>)
{
return get_ptr();
return get_ptr<true>();
}

std::add_lvalue_reference_t<T> operator *() const requires (!std::is_void_v<T>)
{
return *static_cast<T*>(vm::base(vm::cast(m_addr)));
return *get_ptr<true>();
}

std::add_lvalue_reference_t<T> operator [](u32 index) const requires (!std::is_void_v<T>)
{
AUDIT(mAddr);

return *static_cast<T*>(vm::base(vm::cast(m_addr) + u32{sizeof(T)} * index));
}

Expand Down

0 comments on commit 632b74b

Please sign in to comment.