Comments; range-for; fix unchecked dereferences of pointer-to-pointer

This commit is contained in:
Paul Licameli 2021-05-16 08:06:18 -04:00
parent 77b60ebbbb
commit c96d5f12bc
5 changed files with 14 additions and 17 deletions

View File

@ -1487,7 +1487,8 @@ bool AudacityApp::InitPart2()
// Auto-recovery
//
bool didRecoverAnything = false;
if (!ShowAutoRecoveryDialogIfNeeded(&project, &didRecoverAnything))
// This call may reassign project (passed by reference)
if (!ShowAutoRecoveryDialogIfNeeded(project, &didRecoverAnything))
{
QuitAudacity(true);
}
@ -1495,7 +1496,7 @@ bool AudacityApp::InitPart2()
//
// Remainder of command line parsing, but only if we didn't recover
//
if (!didRecoverAnything)
if (project && !didRecoverAnything)
{
if (parser->Found(wxT("t")))
{

View File

@ -36,7 +36,7 @@ enum {
class AutoRecoveryDialog final : public wxDialogWrapper
{
public:
AutoRecoveryDialog(AudacityProject *proj);
explicit AutoRecoveryDialog(AudacityProject *proj);
bool HasRecoverables() const;
FilePaths GetRecoverables();
@ -417,7 +417,7 @@ void AutoRecoveryDialog::OnListKeyDown(wxKeyEvent &evt)
////////////////////////////////////////////////////////////////////////////
static bool RecoverAllProjects(const FilePaths &files,
AudacityProject **pproj)
AudacityProject *&pproj)
{
// Open a project window for each auto save file
wxString filename;
@ -425,12 +425,9 @@ static bool RecoverAllProjects(const FilePaths &files,
for (auto &file: files)
{
AudacityProject *proj = nullptr;
if (*pproj)
{
// Reuse existing project window
proj = *pproj;
*pproj = NULL;
}
// Reuse any existing project window, which will be the empty project
// created at application startup
std::swap(proj, pproj);
// Open project.
if (ProjectManager::OpenProject(proj, file, false) == nullptr)
@ -449,7 +446,7 @@ static void DiscardAllProjects(const FilePaths &files)
ProjectFileManager::DiscardAutosave(file);
}
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject **pproj, bool *didRecoverAnything)
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject *&pproj, bool *didRecoverAnything)
{
if (didRecoverAnything)
{
@ -472,7 +469,7 @@ bool ShowAutoRecoveryDialogIfNeeded(AudacityProject **pproj, bool *didRecoverAny
// This must be done before "dlg" is declared.
wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
AutoRecoveryDialog dialog(*pproj);
AutoRecoveryDialog dialog(pproj);
if (dialog.HasRecoverables())
{

View File

@ -26,7 +26,7 @@ class AudacityProject;
// The didRecoverAnything param is strictly for a return value.
// Any value passed in is ignored.
//
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject** pproj,
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject*& pproj,
bool *didRecoverAnything);
#endif

View File

@ -868,9 +868,7 @@ void ProjectManager::OpenFiles(AudacityProject *proj)
Importer::SetLastOpenType({});
} );
for (size_t ff = 0; ff < selectedFiles.size(); ff++) {
const wxString &fileName = selectedFiles[ff];
for (const auto &fileName : selectedFiles) {
// Make sure it isn't already open.
if (ProjectFileManager::IsAlreadyOpen(fileName))
continue; // Skip ones that are already open.
@ -912,7 +910,7 @@ AudacityProject *ProjectManager::OpenProject(
// Ensure that it happens here: don't wait for the application level
// exception handler, because the exception may be intercepted
ProjectHistory::Get(*pProject).RollbackState();
// Any exception now continues propagating
// Any exception now continues propagating
} );
ProjectFileManager::Get( *pProject ).OpenFile( fileNameArg, addtohistory );

View File

@ -59,6 +59,7 @@ bool OpenProjectCommand::Apply(const CommandContext & context){
auto oldFileName = projectFileIO.GetFileName();
if(mFileName.empty())
{
// This path queries the user for files to open
auto project = &context.project;
ProjectManager::OpenFiles(project);
}