Cleanup: use std::vector rather than a raw array.
authorCarl Hetherington <cth@carlh.net>
Sat, 17 Feb 2024 22:49:27 +0000 (23:49 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 17 Feb 2024 22:49:27 +0000 (23:49 +0100)
src/util.cc

index a030ecb098ab930364b5d57a8e4a550cd112eba7..f5a15944ac6447728fffe1e478949cef2d731d22 100644 (file)
@@ -265,14 +265,13 @@ 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];
+       std::vector<char> buffer(len);
        /* This may read less than `len' if we are on Windows and we have CRLF in the file */
-       int const N = f.read(c, 1, len);
+       int const N = f.read(buffer.data(), 1, len);
+       return string(buffer.data(), N);
+}
 
-       string s (c, N);
-       delete[] c;
 
-       return s;
 }