From d8272b08303b69889a4b702bf269ee0d9b0eb6eb Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 24 Sep 2022 18:40:37 +0100 Subject: [PATCH] pcm: Ensure missing package version properly handled at runtime wxASSERT is removed in release mode (which most users run), so this will not prevent future code from possibly using an invalid iterator if the package version can't actually be found. --- kicad/pcm/pcm_task_manager.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kicad/pcm/pcm_task_manager.cpp b/kicad/pcm/pcm_task_manager.cpp index 325fdbb6b5..3eed36eb35 100644 --- a/kicad/pcm/pcm_task_manager.cpp +++ b/kicad/pcm/pcm_task_manager.cpp @@ -69,7 +69,13 @@ void PCM_TASK_MANAGER::DownloadAndInstall( const PCM_PACKAGE& aPackage, const wx return pv.version == aVersion; } ); - wxASSERT_MSG( find_pkgver != aPackage.versions.end(), "Package version not found" ); + if( find_pkgver == aPackage.versions.end() ) + { + m_reporter->PCMReport( wxString::Format( _( "Version %s of package %s not found!" ), + aVersion, aPackage.identifier ), + RPT_SEVERITY_ERROR ); + return; + } if( !wxDirExists( file_path.GetPath() ) && !wxFileName::Mkdir( file_path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) ) @@ -154,7 +160,13 @@ void PCM_TASK_MANAGER::installDownloadedPackage( const PCM_PACKAGE& aPackage, return pv.version == aVersion; } ); - wxASSERT_MSG( pkgver != aPackage.versions.end(), "Package version not found" ); + if( pkgver == aPackage.versions.end() ) + { + m_reporter->PCMReport( wxString::Format( _( "Version %s of package %s not found!" ), + aVersion, aPackage.identifier ), + RPT_SEVERITY_ERROR ); + return; + } // wxRegEx is not CopyConstructible hence the weird choice of forward_list std::forward_list keep_on_update;