io: don't add a null terminator with slurp

This commit is contained in:
Danny Robson 2016-03-17 18:06:45 +11:00
parent ab330cc520
commit ecb97143cf
2 changed files with 3 additions and 7 deletions

6
io.cpp
View File

@ -47,10 +47,8 @@ util::slurp (const boost::filesystem::path& path) {
if (lseek (out, 0, SEEK_SET) == (off_t)-1)
throw errno_error ();
// Allocate a buffer, and keep reading until it's full. We provide a null
// padding at the tail as a 'just in case' measure for string manipulation.
std::vector<char> buffer (size + 1);
buffer.data ()[size] = '\0';
// Allocate a buffer, and keep reading until it's full.
std::vector<char> buffer (size);
CHECK_GE (size, 0);
size_t remaining = (size_t)size;

4
io.hpp
View File

@ -67,10 +67,8 @@ namespace util {
#endif
/// Reads an entire file into memory. Caller frees the result. Guarantees a
/// null trailing byte.
/// Reads an entire file into memory.
std::vector<char> slurp (const boost::filesystem::path&);
std::vector<char> slurp (FILE *);