diff options
author | Will Dietz <w@wdtz.org> | 2018-03-01T21·00-0600 |
---|---|---|
committer | Will Dietz <w@wdtz.org> | 2018-03-02T16·52-0600 |
commit | c89a3d536891da84403b025c70f1ae225faa0eb2 (patch) | |
tree | c019b3b8ead8a0c609d9a54db70e27904811863e /src/libutil/hash.cc | |
parent | 3748a0ca1e9406ff4a701b4f0e1f506c008c4137 (diff) |
don't allocate large buffers on the stack
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r-- | src/libutil/hash.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 75e4767550f7..8267481b8829 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -256,12 +256,12 @@ Hash hashFile(HashType ht, const Path & path) AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); if (!fd) throw SysError(format("opening file '%1%'") % path); - unsigned char buf[8192]; + std::vector<unsigned char> buf(8192); ssize_t n; - while ((n = read(fd.get(), buf, sizeof(buf)))) { + while ((n = read(fd.get(), buf.data(), buf.size()))) { checkInterrupt(); if (n == -1) throw SysError(format("reading file '%1%'") % path); - update(ht, ctx, buf, n); + update(ht, ctx, buf.data(), n); } finish(ht, ctx, hash.hash); |