From fe6ad813409b42b2e303e35f02e036497cc81141 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 14 Jul 2022 00:30:40 +0200 Subject: [PATCH] Fix copy helper for large data sizes on 32-bit platforms On 32-bit platforms `std::size_t` is just 4 bytes big which is not enough to handle large data sizes. Using `std::streamsize` would likely be most appropriate but switching signdness is likely not the best idea for compatibility and it would mean a comparison with different signdness because the buffer size is still `std::size_t`. So using `std::uint64_t` now. --- io/copy.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/io/copy.h b/io/copy.h index 05c00b7..c5ff8e3 100644 --- a/io/copy.h +++ b/io/copy.h @@ -16,11 +16,11 @@ namespace CppUtilities { template class CPP_UTILITIES_EXPORT CopyHelper { public: CopyHelper(); - void copy(std::istream &input, std::ostream &output, std::size_t count); - void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function &isAborted, + void copy(std::istream &input, std::ostream &output, std::uint64_t count); + void callbackCopy(std::istream &input, std::ostream &output, std::uint64_t count, const std::function &isAborted, const std::function &callback); - void copy(NativeFileStream &input, NativeFileStream &output, std::size_t count); - void callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count, const std::function &isAborted, + void copy(NativeFileStream &input, NativeFileStream &output, std::uint64_t count); + void callbackCopy(NativeFileStream &input, NativeFileStream &output, std::uint64_t count, const std::function &isAborted, const std::function &callback); char *buffer(); @@ -40,7 +40,7 @@ template CopyHelper::CopyHelper() * \remarks Set an exception mask using std::ios::exceptions() to get a std::ios_base::failure exception * when an IO error occurs. */ -template void CopyHelper::copy(std::istream &input, std::ostream &output, std::size_t count) +template void CopyHelper::copy(std::istream &input, std::ostream &output, std::uint64_t count) { while (count > bufferSize) { input.read(m_buffer, bufferSize); @@ -62,7 +62,7 @@ template void CopyHelper::copy(std::istream * when an IO error occurs. */ template -void CopyHelper::callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function &isAborted, +void CopyHelper::callbackCopy(std::istream &input, std::ostream &output, std::uint64_t count, const std::function &isAborted, const std::function &callback) { const auto totalBytes = count; @@ -87,7 +87,7 @@ void CopyHelper::callbackCopy(std::istream &input, std::ostream &out * when an IO error occurs. * - Possibly uses native APIs such as POSIX sendfile() to improve the speed (not implemented yet). */ -template void CopyHelper::copy(NativeFileStream &input, NativeFileStream &output, std::size_t count) +template void CopyHelper::copy(NativeFileStream &input, NativeFileStream &output, std::uint64_t count) { copy(static_cast(input), static_cast(output), count); } @@ -104,7 +104,7 @@ template void CopyHelper::copy(NativeFileSt * - Possibly uses native APIs such as POSIX sendfile() to improve the speed (not implemented yet). */ template -void CopyHelper::callbackCopy(NativeFileStream &input, NativeFileStream &output, std::size_t count, +void CopyHelper::callbackCopy(NativeFileStream &input, NativeFileStream &output, std::uint64_t count, const std::function &isAborted, const std::function &callback) { callbackCopy(static_cast(input), static_cast(output), count, isAborted, callback);