summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-07-23 20:52:32 +0200
committerLioncash <mathew1800@gmail.com>2018-07-23 20:53:54 +0200
commit1432912ae88e750ae0aae8972d7e260538d271df (patch)
treeadb2360ca68a60f3ec03d1902d6e33ff09b27f18 /src/core/hle/service
parentvi: std::move std::vector in constructors where applicable (diff)
downloadyuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar.gz
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar.bz2
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar.lz
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar.xz
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.tar.zst
yuzu-1432912ae88e750ae0aae8972d7e260538d271df.zip
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/vi/vi.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 049957503..993f1e65a 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <memory>
+#include <type_traits>
#include <utility>
#include <boost/optional.hpp>
#include "common/alignment.h"
@@ -44,7 +45,9 @@ public:
template <typename T>
T Read() {
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
ASSERT(read_index + sizeof(T) <= buffer.size());
+
T val;
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
read_index += sizeof(T);
@@ -54,7 +57,9 @@ public:
template <typename T>
T ReadUnaligned() {
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
ASSERT(read_index + sizeof(T) <= buffer.size());
+
T val;
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
read_index += sizeof(T);
@@ -88,8 +93,12 @@ public:
template <typename T>
void Write(const T& val) {
- if (buffer.size() < write_index + sizeof(T))
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
+
+ if (buffer.size() < write_index + sizeof(T)) {
buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize);
+ }
+
std::memcpy(buffer.data() + write_index, &val, sizeof(T));
write_index += sizeof(T);
write_index = Common::AlignUp(write_index, 4);
@@ -97,7 +106,9 @@ public:
template <typename T>
void WriteObject(const T& val) {
- u32_le size = static_cast<u32>(sizeof(val));
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
+
+ const u32_le size = static_cast<u32>(sizeof(val));
Write(size);
// TODO(Subv): Support file descriptors.
Write<u32_le>(0); // Fd count.