diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 49f9969e..e98f2e03 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -9,6 +9,8 @@ #include "Music.h" #include "UtilityClass.h" +#include + scriptclass::scriptclass() { //Start SDL @@ -76,6 +78,8 @@ void scriptclass::tokenize( const std::string& t ) void scriptclass::run() { + // This counter here will stop the function when it gets too high + short execution_counter = 0; while(running && scriptdelay<=0 && !game.pausescript) { if (position < (int) commands.size()) @@ -2603,6 +2607,17 @@ void scriptclass::run() { running = false; } + // Don't increment if we're at the max, signed int overflow is UB + if (execution_counter == SHRT_MAX) + { + // We must be in an infinite loop + printf("Warning: execution counter got to %i, stopping script\n", SHRT_MAX); + running = false; + } + else + { + execution_counter++; + } } if(scriptdelay>0)