From ecb97143cfb86a9ecbee7b4c0869c274c5f67239 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 17 Mar 2016 18:06:45 +1100 Subject: [PATCH] io: don't add a null terminator with slurp --- io.cpp | 6 ++---- io.hpp | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/io.cpp b/io.cpp index 2ea55a60..0b3bab8b 100644 --- a/io.cpp +++ b/io.cpp @@ -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 buffer (size + 1); - buffer.data ()[size] = '\0'; + // Allocate a buffer, and keep reading until it's full. + std::vector buffer (size); CHECK_GE (size, 0); size_t remaining = (size_t)size; diff --git a/io.hpp b/io.hpp index 5c3c26c5..06005bad 100644 --- a/io.hpp +++ b/io.hpp @@ -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 slurp (const boost::filesystem::path&); - std::vector slurp (FILE *);