From c7cbd39720b2b3149bff4851dc680a0fc6f4eaba Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 4 Nov 2015 21:25:36 +0000 Subject: [PATCH] Hopefully fix file_to_string() on Windows with text files. --- src/util.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util.cc b/src/util.cc index 5a5db98d..856bc9bd 100644 --- a/src/util.cc +++ b/src/util.cc @@ -408,12 +408,12 @@ dcp::file_to_string (boost::filesystem::path p, uintmax_t max_length) throw FileError ("could not open file", p, errno); } - char* c = new char[len + 1]; - fread (c, 1, len, f); + char* c = new char[len]; + /* This may read less than `len' if we are on Windows and we have CRLF in the file */ + int const N = fread (c, 1, len, f); fclose (f); - c[len] = '\0'; - string s (c); + string s (c, N); delete[] c; return s; -- 2.30.2