Commit 6bd3880c authored by Victor Zverovich's avatar Victor Zverovich

Fix test.

parent 6a5f27be
...@@ -102,9 +102,19 @@ void File::close() { ...@@ -102,9 +102,19 @@ void File::close() {
fmt::ThrowSystemError(errno, "cannot close file"); fmt::ThrowSystemError(errno, "cannot close file");
} }
#ifdef _WIN32
// On Windows the count argument to read and write is unsigned, so convert
// it from size_t preventing integer overflow.
inline unsigned ConvertRWCount(std::size_t count) {
return count <= UINT_MAX ? count : UINT_MAX;
}
#else
inline std::size_t ConvertRWCount(std::size_t count) { return count; }
#endif
std::streamsize File::read(void *buffer, std::size_t count) { std::streamsize File::read(void *buffer, std::size_t count) {
std::streamsize result = 0; std::streamsize result = 0;
FMT_RETRY(result, ::FMT_POSIX(read(fd_, buffer, count))); FMT_RETRY(result, ::FMT_POSIX(read(fd_, buffer, ConvertRWCount(count))));
if (result == -1) if (result == -1)
fmt::ThrowSystemError(errno, "cannot read from file"); fmt::ThrowSystemError(errno, "cannot read from file");
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment