mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
fix(system/file): use 64-bit math when copying files
This commit is contained in:
parent
d0f9939077
commit
581522ca0f
2 changed files with 10 additions and 7 deletions
|
|
@ -275,13 +275,13 @@ bool Copy(File::Filesystem* fs, Stacked::FileParms* parms) {
|
||||||
auto sz_source = File::GetFileInfo(st_source)->size;
|
auto sz_source = File::GetFileInfo(st_source)->size;
|
||||||
|
|
||||||
// copybuffer size upper limit is BC_FILE_SYSTEM_COPYBUFFER_SIZE
|
// copybuffer size upper limit is BC_FILE_SYSTEM_COPYBUFFER_SIZE
|
||||||
size_t sz_copybuffer = std::min(static_cast<size_t>(sz_source), static_cast<size_t>(BC_FILE_SYSTEM_COPYBUFFER_SIZE));
|
uint64_t sz_copybuffer = std::min(sz_source, static_cast<uint64_t>(BC_FILE_SYSTEM_COPYBUFFER_SIZE));
|
||||||
auto u8_copybuffer = reinterpret_cast<uint8_t*>(Memory::Allocate(sz_copybuffer));
|
auto u8_copybuffer = reinterpret_cast<uint8_t*>(Memory::Allocate(sz_copybuffer));
|
||||||
|
|
||||||
// Loop through the source file, reading segments into 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
|
// How many bytes to read
|
||||||
size_t sz_bytesToRead = sz_source - std::min(index+sz_copybuffer, sz_source);
|
size_t sz_bytesToRead = static_cast<size_t>(sz_source - std::min(index+sz_copybuffer, sz_source));
|
||||||
size_t sz_bytesRead = 0;
|
size_t sz_bytesRead = 0;
|
||||||
size_t sz_bytesWritten = 0;
|
size_t sz_bytesWritten = 0;
|
||||||
// Read data segment into copybuffer
|
// Read data segment into copybuffer
|
||||||
|
|
@ -311,6 +311,9 @@ bool Copy(File::Filesystem* fs, Stacked::FileParms* parms) {
|
||||||
|
|
||||||
// Success!
|
// Success!
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Success!
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Open(File::Filesystem* fs, Stacked::FileParms* parms) {
|
bool Open(File::Filesystem* fs, Stacked::FileParms* parms) {
|
||||||
|
|
|
||||||
|
|
@ -472,13 +472,13 @@ bool Copy(FileParms* parms) {
|
||||||
auto sz_source = File::GetFileInfo(st_source)->size;
|
auto sz_source = File::GetFileInfo(st_source)->size;
|
||||||
|
|
||||||
// copybuffer size upper limit is BC_FILE_SYSTEM_COPYBUFFER_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));
|
uint64_t sz_copybuffer = std::min(sz_source, static_cast<uint64_t>(BC_FILE_SYSTEM_COPYBUFFER_SIZE));
|
||||||
auto u8_copybuffer = reinterpret_cast<uint8_t*>(Memory::Allocate(sz_copybuffer));
|
auto u8_copybuffer = reinterpret_cast<uint8_t*>(Memory::Allocate(sz_copybuffer));
|
||||||
|
|
||||||
// Loop through the source file, reading segments into copybuffer
|
// Loop through the source file, reading segments into copybuffer
|
||||||
for (uint64_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
|
// How many bytes to read
|
||||||
size_t sz_bytesToRead = sz_source - std::min(index+sz_copybuffer, sz_source);
|
size_t sz_bytesToRead = static_cast<size_t>(sz_source - std::min(index+sz_copybuffer, sz_source));
|
||||||
size_t sz_bytesRead = 0;
|
size_t sz_bytesRead = 0;
|
||||||
size_t sz_bytesWritten = 0;
|
size_t sz_bytesWritten = 0;
|
||||||
// Read data segment into copybuffer
|
// Read data segment into copybuffer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue