1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 06:21:14 +02:00

don't allocate large buffers on the stack

This commit is contained in:
Will Dietz 2018-03-01 15:00:58 -06:00
parent 3748a0ca1e
commit c89a3d5368
5 changed files with 30 additions and 29 deletions

View file

@ -37,13 +37,13 @@ using namespace nix;
static ssize_t splice(int fd_in, void *off_in, int fd_out, void *off_out, size_t len, unsigned int flags)
{
/* We ignore most parameters, we just have them for conformance with the linux syscall */
char buf[8192];
auto read_count = read(fd_in, buf, sizeof(buf));
std::vector<char> buf(8192);
auto read_count = read(fd_in, buf.data(), buf.size());
if (read_count == -1)
return read_count;
auto write_count = decltype(read_count)(0);
while (write_count < read_count) {
auto res = write(fd_out, buf + write_count, read_count - write_count);
auto res = write(fd_out, buf.data() + write_count, read_count - write_count);
if (res == -1)
return res;
write_count += res;