summaryrefslogtreecommitdiff
path: root/src/common/file_util.h
diff options
context:
space:
mode:
authorGravatar Lioncash2018-04-29 18:18:39 -0400
committerGravatar Lioncash2018-04-29 18:24:12 -0400
commit40d2dcabd7e5b978c0e1e5c76000de01e2d0c270 (patch)
tree7749359774badad9b2bd602a69aa4a625fcb46ee /src/common/file_util.h
parentMerge pull request #421 from Subv/sh_pred3 (diff)
downloadyuzu-40d2dcabd7e5b978c0e1e5c76000de01e2d0c270.tar.gz
yuzu-40d2dcabd7e5b978c0e1e5c76000de01e2d0c270.tar.xz
yuzu-40d2dcabd7e5b978c0e1e5c76000de01e2d0c270.zip
file_util: Add static assertions to ReadBytes() and WriteBytes()
Ensure that the actual types being passed in are trivially copyable. The internal call to ReadArray() and WriteArray() will always succeed, since they're passed a pointer to char* which is always trivially copyable.
Diffstat (limited to 'src/common/file_util.h')
-rw-r--r--src/common/file_util.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 4c11849ee..32ff4d8ca 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -202,11 +202,15 @@ public:
202 return items_written; 202 return items_written;
203 } 203 }
204 204
205 size_t ReadBytes(void* data, size_t length) { 205 template <typename T>
206 size_t ReadBytes(T* data, size_t length) {
207 static_assert(std::is_trivially_copyable<T>(), "T must be trivially copyable");
206 return ReadArray(reinterpret_cast<char*>(data), length); 208 return ReadArray(reinterpret_cast<char*>(data), length);
207 } 209 }
208 210
209 size_t WriteBytes(const void* data, size_t length) { 211 template <typename T>
212 size_t WriteBytes(const T* data, size_t length) {
213 static_assert(std::is_trivially_copyable<T>(), "T must be trivially copyable");
210 return WriteArray(reinterpret_cast<const char*>(data), length); 214 return WriteArray(reinterpret_cast<const char*>(data), length);
211 } 215 }
212 216