Skip to content

Commit

Permalink
Handle large buffers in file::read
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Jan 1, 2025
1 parent bb6aa76 commit 608c13c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ std::string file::read() const {

std::size_t offset = 0;
while (offset < content.size()) {
// FIXME: handle large buffers
#ifdef _WIN32
int bytes_read = _read(handle, &content[offset], content.size() - offset);
#else
ssize_t bytes_read = ::read(handle, &content[offset], content.size() - offset);
#endif
// `read` will fail if the parameter `nbyte` exceeds `INT_MAX`
int nbyte = static_cast<int>(std::min<size_t>(content.size() - offset, INT_MAX));
auto bytes_read = ::read(handle, &content[offset], nbyte);

if (bytes_read == 0) {
break;
Expand Down

0 comments on commit 608c13c

Please sign in to comment.