From bf9f3ec4f0a987ae1591ab5466f6eee599203c85 Mon Sep 17 00:00:00 2001 From: Jertzukka Date: Tue, 4 Jun 2024 00:10:53 +0300 Subject: Avoid assert by verifying installed languages exist (#1354) wxDir::GetAllFiles will throw an assert when opening the preferences dialog if for some reason the user has not installed VeraCrypt properly and is missing the intended folder. This patch adds a check to ensure the folder first exists before querying its files. --- src/Main/Forms/PreferencesDialog.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Main/Forms/PreferencesDialog.cpp b/src/Main/Forms/PreferencesDialog.cpp index 90a668e6..c4d5140f 100644 --- a/src/Main/Forms/PreferencesDialog.cpp +++ b/src/Main/Forms/PreferencesDialog.cpp @@ -82,14 +82,16 @@ namespace VeraCrypt LanguageListBox->Append("System default"); LanguageListBox->Append("English"); - size_t langCount; - langCount = wxDir::GetAllFiles(languagesFolder.GetName(), &langArray, wxEmptyString, wxDIR_FILES); - for (size_t i = 0; i < langCount; ++i) { - wxFileName filename(langArray[i]); - wxString langId = filename.GetName().AfterLast('.'); - wxString langNative = langEntries[langId]; - if (!langNative.empty()) { - LanguageListBox->Append(langNative); + if (wxDir::Exists(languagesFolder.GetName())) { + size_t langCount; + langCount = wxDir::GetAllFiles(languagesFolder.GetName(), &langArray, wxEmptyString, wxDIR_FILES); + for (size_t i = 0; i < langCount; ++i) { + wxFileName filename(langArray[i]); + wxString langId = filename.GetName().AfterLast('.'); + wxString langNative = langEntries[langId]; + if (!langNative.empty()) { + LanguageListBox->Append(langNative); + } } } #endif -- cgit v1.2.3