Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87daae55 authored by Stephen Hines's avatar Stephen Hines Committed by android-build-merger
Browse files

Merge "Switch to memcpy for accessing misaligned data."

am: 2bdb3719

Change-Id: I3869562aef3d54316af6c72edf1fb8264ce28cb3
parents 4fee4601 2bdb3719
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -20,25 +20,19 @@
namespace android {
namespace base {

// Use packed structures for access to unaligned data on targets with alignment
// Use memcpy for access to unaligned data on targets with alignment
// restrictions.  The compiler will generate appropriate code to access these
// structures without generating alignment exceptions.
template <typename T>
static inline T get_unaligned(const T* address) {
  struct unaligned {
    T v;
  } __attribute__((packed));
  const unaligned* p = reinterpret_cast<const unaligned*>(address);
  return p->v;
static inline T get_unaligned(const void* address) {
  T result;
  memcpy(&result, address, sizeof(T));
  return result;
}

template <typename T>
static inline void put_unaligned(T* address, T v) {
  struct unaligned {
    T v;
  } __attribute__((packed));
  unaligned* p = reinterpret_cast<unaligned*>(address);
  p->v = v;
static inline void put_unaligned(void* address, T v) {
  memcpy(address, &v, sizeof(T));
}

} // namespace base
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public:
    }

    bool DoVerify(const password_handle_t *expected_handle, const SizedBuffer &password) {
        uint64_t user_id = android::base::get_unaligned(&expected_handle->user_id);
        uint64_t user_id = android::base::get_unaligned<secure_id_t>(&expected_handle->user_id);
        FastHashMap::const_iterator it = fast_hash_map_.find(user_id);
        if (it != fast_hash_map_.end() && VerifyFast(it->second, password)) {
            return true;