Browse Source
Merge pull request #4489 from lioncash/typesafe
ipc_helpers: Only allow trivially copyable objects with PushRaw() and PopRaw()
pull/15/merge
bunnei
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
4 additions and
0 deletions
-
src/core/hle/ipc_helpers.h
|
|
|
@ -229,6 +229,8 @@ inline void ResponseBuilder::Push(u32 value) { |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void ResponseBuilder::PushRaw(const T& value) { |
|
|
|
static_assert(std::is_trivially_copyable_v<T>, |
|
|
|
"It's undefined behavior to use memcpy with non-trivially copyable objects"); |
|
|
|
std::memcpy(cmdbuf + index, &value, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
@ -384,6 +386,8 @@ inline s32 RequestParser::Pop() { |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void RequestParser::PopRaw(T& value) { |
|
|
|
static_assert(std::is_trivially_copyable_v<T>, |
|
|
|
"It's undefined behavior to use memcpy with non-trivially copyable objects"); |
|
|
|
std::memcpy(&value, cmdbuf + index, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
|