Skip to content
Snippets Groups Projects
Commit 0735a0c8 authored by Lioncash's avatar Lioncash
Browse files

file_util: Avoid sign-conversions in WriteArray() and ReadArray()

Prevents compiler warnings.
parent c392650e
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <limits>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <type_traits> #include <type_traits>
...@@ -210,8 +211,9 @@ public: ...@@ -210,8 +211,9 @@ public:
static_assert(std::is_trivially_copyable<T>(), static_assert(std::is_trivially_copyable<T>(),
"Given array does not consist of trivially copyable objects"); "Given array does not consist of trivially copyable objects");
if (!IsOpen()) if (!IsOpen()) {
return -1; return std::numeric_limits<size_t>::max();
}
return std::fread(data, sizeof(T), length, m_file); return std::fread(data, sizeof(T), length, m_file);
} }
...@@ -220,8 +222,10 @@ public: ...@@ -220,8 +222,10 @@ public:
size_t WriteArray(const T* data, size_t length) { size_t WriteArray(const T* data, size_t length) {
static_assert(std::is_trivially_copyable<T>(), static_assert(std::is_trivially_copyable<T>(),
"Given array does not consist of trivially copyable objects"); "Given array does not consist of trivially copyable objects");
if (!IsOpen()) if (!IsOpen()) {
return -1; return std::numeric_limits<size_t>::max();
}
return std::fwrite(data, sizeof(T), length, m_file); return std::fwrite(data, sizeof(T), length, m_file);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment