diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-11-04 21:25:36 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-11-04 21:25:36 +0000 |
| commit | c7cbd39720b2b3149bff4851dc680a0fc6f4eaba (patch) | |
| tree | 4e67238e29272b2adc879416dd4553a4b4bbb868 /src/util.cc | |
| parent | 7c96eeaad4586641c5e7a4b00c10138ec0b49c79 (diff) | |
Hopefully fix file_to_string() on Windows with text files.
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 8 |
1 files 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; |
