From 581522ca0ff1f3bf622a809a8286c34428737ab0 Mon Sep 17 00:00:00 2001 From: superp00t Date: Mon, 14 Aug 2023 20:40:09 -0400 Subject: [PATCH] fix(system/file): use 64-bit math when copying files --- bc/system/file/posix/System_File.cpp | 11 +++++++---- bc/system/file/win/Stacked.cpp | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bc/system/file/posix/System_File.cpp b/bc/system/file/posix/System_File.cpp index 549f220..2c818d4 100644 --- a/bc/system/file/posix/System_File.cpp +++ b/bc/system/file/posix/System_File.cpp @@ -275,13 +275,13 @@ bool Copy(File::Filesystem* fs, Stacked::FileParms* parms) { auto sz_source = File::GetFileInfo(st_source)->size; // copybuffer size upper limit is BC_FILE_SYSTEM_COPYBUFFER_SIZE - size_t sz_copybuffer = std::min(static_cast(sz_source), static_cast(BC_FILE_SYSTEM_COPYBUFFER_SIZE)); - auto u8_copybuffer = reinterpret_cast(Memory::Allocate(sz_copybuffer)); + uint64_t sz_copybuffer = std::min(sz_source, static_cast(BC_FILE_SYSTEM_COPYBUFFER_SIZE)); + auto u8_copybuffer = reinterpret_cast(Memory::Allocate(sz_copybuffer)); // Loop through the source file, reading segments into copybuffer - for (size_t index = 0; index < sz_source; index += sz_copybuffer) { + for (uint64_t index = 0; index < sz_source; index += sz_copybuffer) { // How many bytes to read - size_t sz_bytesToRead = sz_source - std::min(index+sz_copybuffer, sz_source); + size_t sz_bytesToRead = static_cast(sz_source - std::min(index+sz_copybuffer, sz_source)); size_t sz_bytesRead = 0; size_t sz_bytesWritten = 0; // Read data segment into copybuffer @@ -311,6 +311,9 @@ bool Copy(File::Filesystem* fs, Stacked::FileParms* parms) { // Success! return true; + + // Success! + return true; } bool Open(File::Filesystem* fs, Stacked::FileParms* parms) { diff --git a/bc/system/file/win/Stacked.cpp b/bc/system/file/win/Stacked.cpp index 295421e..b093f92 100644 --- a/bc/system/file/win/Stacked.cpp +++ b/bc/system/file/win/Stacked.cpp @@ -472,13 +472,13 @@ bool Copy(FileParms* parms) { auto sz_source = File::GetFileInfo(st_source)->size; // copybuffer size upper limit is BC_FILE_SYSTEM_COPYBUFFER_SIZE - size_t sz_copybuffer = std::min(sz_source, uint64_t(BC_FILE_SYSTEM_COPYBUFFER_SIZE)); - auto u8_copybuffer = reinterpret_cast(Memory::Allocate(sz_copybuffer)); + uint64_t sz_copybuffer = std::min(sz_source, static_cast(BC_FILE_SYSTEM_COPYBUFFER_SIZE)); + auto u8_copybuffer = reinterpret_cast(Memory::Allocate(sz_copybuffer)); // Loop through the source file, reading segments into copybuffer for (uint64_t index = 0; index < sz_source; index += sz_copybuffer) { // How many bytes to read - size_t sz_bytesToRead = sz_source - std::min(index+sz_copybuffer, sz_source); + size_t sz_bytesToRead = static_cast(sz_source - std::min(index+sz_copybuffer, sz_source)); size_t sz_bytesRead = 0; size_t sz_bytesWritten = 0; // Read data segment into copybuffer