1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-09 13:12:17 +01:00

Exception safety in: subclasses of ExportPlugin; and more error checking

This commit is contained in:
Paul Licameli
2016-12-24 08:57:27 -05:00
parent 48459404a5
commit 0c8bedc59a
8 changed files with 156 additions and 95 deletions

View File

@@ -1809,6 +1809,9 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
long bytes;
size_t bufferSize = std::max(0, exporter.GetOutBufferSize());
if (bufferSize == 0)
return ProgressResult::Cancelled;
ArrayOf<unsigned char> buffer{ bufferSize };
wxASSERT(buffer);
@@ -1873,6 +1876,7 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
wxString msg;
msg.Printf(_("Error %ld returned from MP3 encoder"), bytes);
wxMessageBox(msg);
updateResult = ProgressResult::Cancelled;
break;
}
@@ -1882,28 +1886,29 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
}
}
bytes = exporter.FinishStream(buffer.get());
if ( updateResult != ProgressResult::Cancelled ) {
bytes = exporter.FinishStream(buffer.get());
if (bytes) {
outFile.Write(buffer.get(), bytes);
if (bytes > 0) {
outFile.Write(buffer.get(), bytes);
}
// Write ID3 tag if it was supposed to be at the end of the file
if (id3len > 0 && endOfFile) {
outFile.Write(id3buffer.get(), id3len);
}
// Always write the info (Xing/Lame) tag. Until we stop supporting Lame
// versions before 3.98, we must do this after the MP3 file has been
// closed.
//
// Also, if beWriteInfoTag() is used, mGF will no longer be valid after
// this call, so do not use it.
exporter.PutInfoTag(outFile, pos);
outFile.Close();
}
// Write ID3 tag if it was supposed to be at the end of the file
if (id3len && endOfFile) {
outFile.Write(id3buffer.get(), id3len);
}
// Always write the info (Xing/Lame) tag. Until we stop supporting Lame
// versions before 3.98, we must do this after the MP3 file has been
// closed.
//
// Also, if beWriteInfoTag() is used, mGF will no longer be valid after
// this call, so do not use it.
exporter.PutInfoTag(outFile, pos);
// Close the file
outFile.Close();
return updateResult;
}