diff options
| author | 2018-08-07 22:37:00 -0400 | |
|---|---|---|
| committer | 2018-08-07 22:37:00 -0400 | |
| commit | 80cfd88e4ec5d2862227dedef5b9f709a8350319 (patch) | |
| tree | d6fc13f86efe54ca4a6aec0c5a95ca56c5ca42cf /src | |
| parent | Merge pull request #971 from DarkLordZach/mbedtls-2.12.0 (diff) | |
| parent | file_util: Avoid sign-conversions in WriteArray() and ReadArray() (diff) | |
| download | yuzu-80cfd88e4ec5d2862227dedef5b9f709a8350319.tar.gz yuzu-80cfd88e4ec5d2862227dedef5b9f709a8350319.tar.xz yuzu-80cfd88e4ec5d2862227dedef5b9f709a8350319.zip | |
Merge pull request #967 from lioncash/sign
file_util: Avoid sign-conversions in WriteArray() and ReadArray()
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/file_util.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index 28697d527..430dac41c 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <cstdio> | 8 | #include <cstdio> |
| 9 | #include <fstream> | 9 | #include <fstream> |
| 10 | #include <functional> | 10 | #include <functional> |
| 11 | #include <limits> | ||
| 11 | #include <string> | 12 | #include <string> |
| 12 | #include <string_view> | 13 | #include <string_view> |
| 13 | #include <type_traits> | 14 | #include <type_traits> |
| @@ -210,8 +211,9 @@ public: | |||
| 210 | static_assert(std::is_trivially_copyable<T>(), | 211 | static_assert(std::is_trivially_copyable<T>(), |
| 211 | "Given array does not consist of trivially copyable objects"); | 212 | "Given array does not consist of trivially copyable objects"); |
| 212 | 213 | ||
| 213 | if (!IsOpen()) | 214 | if (!IsOpen()) { |
| 214 | return -1; | 215 | return std::numeric_limits<size_t>::max(); |
| 216 | } | ||
| 215 | 217 | ||
| 216 | return std::fread(data, sizeof(T), length, m_file); | 218 | return std::fread(data, sizeof(T), length, m_file); |
| 217 | } | 219 | } |
| @@ -220,8 +222,10 @@ public: | |||
| 220 | size_t WriteArray(const T* data, size_t length) { | 222 | size_t WriteArray(const T* data, size_t length) { |
| 221 | static_assert(std::is_trivially_copyable<T>(), | 223 | static_assert(std::is_trivially_copyable<T>(), |
| 222 | "Given array does not consist of trivially copyable objects"); | 224 | "Given array does not consist of trivially copyable objects"); |
| 223 | if (!IsOpen()) | 225 | if (!IsOpen()) { |
| 224 | return -1; | 226 | return std::numeric_limits<size_t>::max(); |
| 227 | } | ||
| 228 | |||
| 225 | return std::fwrite(data, sizeof(T), length, m_file); | 229 | return std::fwrite(data, sizeof(T), length, m_file); |
| 226 | } | 230 | } |
| 227 | 231 | ||