Skip to content

Commit

Permalink
Utility: Simplify store
Browse files Browse the repository at this point in the history
  • Loading branch information
cursey committed Apr 20, 2023
1 parent 6d33df8 commit caaea53
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions include/safetyhook/utility.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#pragma once

#include <algorithm>
#include <cstdint>

namespace safetyhook {
template <typename T> constexpr void store(uint8_t* address, const T& value) {
const auto data = reinterpret_cast<const uint8_t*>(&value);

// Write each byte out individually to avoid undefined behavior.
for (size_t i = 0; i < sizeof(T); ++i) {
address[i] = data[i];
}
std::copy_n(reinterpret_cast<const uint8_t*>(&value), sizeof(T), address);
}
} // namespace safetyhook

0 comments on commit caaea53

Please sign in to comment.