From 93ec5783d57d93a294f3ad143a4403a80dfbca4b Mon Sep 17 00:00:00 2001 From: AllyTally Date: Sat, 8 Feb 2020 00:39:05 -0400 Subject: [PATCH] Fix undefined behavior when activating scripts It turns out that the line `tstring=tstring[tstring.size()-1];` also appears once in Scripts.cpp. This causes the game to segfault after activating a terminal with an empty line at the end of it. I added a quick `if` around this line, and set `tstring` to an empty string when needed. --- desktop_version/src/Scripts.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Scripts.cpp b/desktop_version/src/Scripts.cpp index c03e9254..771dfec9 100644 --- a/desktop_version/src/Scripts.cpp +++ b/desktop_version/src/Scripts.cpp @@ -40,7 +40,11 @@ void scriptclass::load(std::string t) }else if(scriptend==-1){ //Find the end tstring=script.customscript[i]; - tstring=tstring[tstring.size()-1]; + if (tstring.size() > 0) { + tstring=tstring[tstring.size()-1]; + } else { + tstring=""; + } if(tstring==":"){ scriptend=i; }