From ffb4240710652b5d1714ef74666d12bf5c2841e4 Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 6 Jan 2020 01:25:35 +0000 Subject: [PATCH] Report failure when a mission is not found in the mission list AlumiuN reported a crash when a save game is unable to load the underlying mission. The crash is because the game proceeds to load the savegame onto whatever level was loaded before this mission, which will usually result in fatal inconsistencies in the data. This commit does not fix the cause of the inability to load the mission, but instead fixes the logic so that the user gets a reasonable error message advising that the mission failed to load. This was unintentionally broken in db80a88ad2c1 when the sense of the return value was inverted, and the fallthrough case was not adjusted. This impacts all uses of `load_mission_by_name`, though in practice restoring from a savegame is the most obvious way to hit the problem. Reported-by: AlumiuN (indirectly) Fixes: db80a88ad2c1af3f4ea260125970b1e496c605ed ("Improve error message on failure to load mission") --- similar/main/mission.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index d60bce3fe..e9428d390 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -1127,15 +1127,10 @@ static const char *load_mission(const mle *const mission) const char *load_mission_by_name(const char *const mission_name) { auto mission_list = build_mission_list(1); - const char *found = nullptr; - range_for (auto &i, mission_list) if (!d_stricmp(mission_name, &*i.filename)) - { - found = load_mission(&i); - break; - } - return found; + return load_mission(&i); + return "No matching mission found in\ninstalled mission list."; } namespace {