diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-10-11 19:55:06 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-10-11 20:13:21 +0200 |
| commit | 44b69f2d9affb048c3d166e3a62bf3462dd5c8b5 (patch) | |
| tree | 7cf2a540d01c66f9a7d12acfdabd0ee2f4251c80 /src/lib/ext.cc | |
| parent | 805d4a48fa6e4d8e28fd582a2ae6ba78b8343144 (diff) | |
Replace some raw arrays with std::vectors.
Diffstat (limited to 'src/lib/ext.cc')
| -rw-r--r-- | src/lib/ext.cc | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/lib/ext.cc b/src/lib/ext.cc index feba68c1f..863cc0307 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -106,7 +106,7 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total throw CopyError (String::compose("Failed to open file %1", from.string()), 0); } - uint8_t* buffer = new uint8_t[block_size]; + std::vector<uint8_t> buffer(block_size); Digester digester; int progress_frequency = 1; @@ -114,28 +114,25 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total uint64_t remaining = file_size (from); while (remaining > 0) { uint64_t const this_time = min(remaining, block_size); - size_t read = fread (buffer, 1, this_time, in); + size_t read = fread (buffer.data(), 1, this_time, in); if (read != this_time) { fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0); } - digester.add (buffer, this_time); + digester.add (buffer.data(), this_time); size_t written; - r = ext4_fwrite (&out, buffer, this_time, &written); + r = ext4_fwrite (&out, buffer.data(), this_time, &written); if (r != EOK) { fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError ("Write failed", r); } if (written != this_time) { fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError (String::compose("Short write; expected %1 but wrote %2", this_time, written), 0); } remaining -= this_time; @@ -149,7 +146,6 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total fclose (in); ext4_fclose (&out); - delete[] buffer; return digester.get (); } @@ -167,21 +163,20 @@ read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_ } LOG_DISK("Opened %1 for read", to.generic_string()); - uint8_t* buffer = new uint8_t[block_size]; + std::vector<uint8_t> buffer(block_size); Digester digester; uint64_t remaining = file_size (from); while (remaining > 0) { uint64_t const this_time = min(remaining, block_size); size_t read; - r = ext4_fread (&in, buffer, this_time, &read); + r = ext4_fread (&in, buffer.data(), this_time, &read); if (read != this_time) { ext4_fclose (&in); - delete[] buffer; throw VerifyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0); } - digester.add (buffer, this_time); + digester.add (buffer.data(), this_time); remaining -= this_time; total_remaining -= this_time; if (nanomsg) { @@ -190,7 +185,6 @@ read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_ } ext4_fclose (&in); - delete[] buffer; return digester.get (); } |
