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) if (lseek (out, 0, SEEK_SET) == (off_t)-1)
throw errno_error (); throw errno_error ();
// Allocate a buffer, and keep reading until it's full. We provide a null // Allocate a buffer, and keep reading until it's full.
// padding at the tail as a 'just in case' measure for string manipulation. std::vector<char> buffer (size);
std::vector<char> buffer (size + 1);
buffer.data ()[size] = '\0';
CHECK_GE (size, 0); CHECK_GE (size, 0);
size_t remaining = (size_t)size; size_t remaining = (size_t)size;

4
io.hpp
View File

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