Use std::array instead of C array

This commit is contained in:
Kovid Goyal 2023-01-28 13:52:15 +05:30
parent 32155c172c
commit 9dd2b16fe9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -675,7 +675,7 @@ save_stream(SpeechSynthesisStream const &&stream, std::filesystem::path path, id
DataReader reader(stream); DataReader reader(stream);
unsigned int n; unsigned int n;
const static unsigned int chunk_size = 16 * 1024; const static unsigned int chunk_size = 16 * 1024;
uint8_t buf[chunk_size]; std::array<uint8_t, chunk_size> buf;
std::ofstream outfile; std::ofstream outfile;
bool ok = false; bool ok = false;
try { try {
@ -693,8 +693,8 @@ save_stream(SpeechSynthesisStream const &&stream, std::filesystem::path path, id
bytes_read += n; bytes_read += n;
ok = false; ok = false;
try { try {
reader.ReadBytes(winrt::array_view(buf, buf + n)); reader.ReadBytes(winrt::array_view(buf.data(), buf.data() + n));
outfile.write((const char*)buf, n); outfile.write((const char*)buf.data(), n);
if (!outfile.good()) throw "Failed to write to output file"; if (!outfile.good()) throw "Failed to write to output file";
ok = true; ok = true;
} CATCH_ALL_EXCEPTIONS("Failed to save bytes from DataReader to file", cmd_id); } CATCH_ALL_EXCEPTIONS("Failed to save bytes from DataReader to file", cmd_id);