From 8567d161b5727d89d08db07bdcd47406624db30d Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Mon, 16 Nov 2020 17:51:09 -0800 Subject: [PATCH] Add defensive checks on index and iterators --- .vscode/settings.json | 5 +++++ src/editor.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..06caa9d9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "map": "cpp" + } +} \ No newline at end of file diff --git a/src/editor.cpp b/src/editor.cpp index 85cc7fd1..241c1600 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -374,13 +374,22 @@ void Editor::deleteWildMonGroup() { if (msgBox.clickedButton() == deleteButton) { auto it = project->wildMonData.find(map->constantName); - it.value().erase(labelCombo->currentText()); + if (it == project->wildMonData.end()) { + logError(QString("Failed to find data for map %s. Unable to delete").arg(map->constantName)); + return; + } int i = project->encounterGroupLabels.indexOf(labelCombo->currentText()); + if (i < 0) { + logError(QString("Failed to find selected wild mon group: %s. Unable to delete") + .arg(labelCombo->currentText())); + return; + } + + it.value().erase(labelCombo->currentText()); project->encounterGroupLabels.remove(i); displayWildMonTables(); - emit wildMonDataChanged(); } }