Skip to content

Commit

Permalink
Merge pull request #14018 from glebm/fix-ubsan-warning-x64-emitter
Browse files Browse the repository at this point in the history
x64Emitter: Fix unaligned store UBSAN errors
  • Loading branch information
hrydgard authored Jan 30, 2021
2 parents a367191 + 7305ba9 commit 53b249f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Common/x64Emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ void XEmitter::SetJumpTarget(const FixupBranch &branch)
{
s64 distance = (s64)(code - branch.ptr);
_assert_msg_(distance >= -0x80000000LL && distance < 0x80000000LL, "Jump target too far away, needs indirect register");
((s32*)branch.ptr)[-1] = (s32)distance;
const s32 distance32 = static_cast<s32>(distance);
std::memcpy(branch.ptr - sizeof(s32), &distance32, sizeof(s32));
}
}

Expand Down
7 changes: 4 additions & 3 deletions Common/x64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ppsspp_config.h"

#include <cstddef>
#include <cstring>

#include "Common/Common.h"
#include "Common/Log.h"
Expand Down Expand Up @@ -361,9 +362,9 @@ class XEmitter

protected:
inline void Write8(u8 value) {*code++ = value;}
inline void Write16(u16 value) {*(u16*)code = (value); code += 2;}
inline void Write32(u32 value) {*(u32*)code = (value); code += 4;}
inline void Write64(u64 value) {*(u64*)code = (value); code += 8;}
inline void Write16(u16 value) {std::memcpy(code, &value, sizeof(u16)); code += 2;}
inline void Write32(u32 value) {std::memcpy(code, &value, sizeof(u32)); code += 4;}
inline void Write64(u64 value) {std::memcpy(code, &value, sizeof(u64)); code += 8;}

public:
XEmitter() { code = nullptr; flags_locked = false; }
Expand Down

0 comments on commit 53b249f

Please sign in to comment.