From 3e35667d102382398aa701a883f1fd951eed0ee3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sat, 10 Dec 2016 12:59:17 +0700 Subject: [PATCH] Fix a crash when map contains a negative number of hotspots --- Source/GameTick.cpp | 4 ++++ Source/main.cpp | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index a8a5cfb..efd06e7 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -992,6 +992,10 @@ void Game::Loadlevel(const std::string& name) if (mapvers >= 7) { int numhotspots; funpackf(tfile, "Bi", &numhotspots); + if (numhotspots < 0) { + cerr << "Map " << name << " have an invalid number of hotspots" << endl; + numhotspots = 0; + } Hotspot::hotspots.resize(numhotspots); for (int i = 0; i < Hotspot::hotspots.size(); i++) { funpackf(tfile, "Bi Bf Bf Bf Bf", &Hotspot::hotspots[i].type, &Hotspot::hotspots[i].size, &Hotspot::hotspots[i].position.x, &Hotspot::hotspots[i].position.y, &Hotspot::hotspots[i].position.z); diff --git a/Source/main.cpp b/Source/main.cpp index 4ff4ebc..e0bf430 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -626,7 +626,7 @@ int main(int argc, char **argv) LOGFUNC; - try { + //~ try { { newGame(); @@ -677,16 +677,16 @@ int main(int argc, char **argv) CleanUp (); return 0; - } catch (const std::exception& error) { - CleanUp(); + //~ } catch (const std::exception& error) { + //~ CleanUp(); - std::string e = "Caught exception: "; - e += error.what(); + //~ std::string e = "Caught exception: "; + //~ e += error.what(); - LOG(e); + //~ LOG(e); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Exception catched", error.what(), NULL); + //~ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Exception catched", error.what(), NULL); - return -1; - } + //~ return -1; + //~ } } -- 2.39.5