mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39:43 +01:00
Fix undefined behavior while loading scripts
In `editor.cpp`, there's a few sections of code that try and index stuff using `string.length()-1`. This causes issues where if the string is empty, the result is -1, causing undefined behavior. Flibit fixed a few of these cases, like on line `375` of editor.cpp: `if((int) tstring.length() - 1 >= 0) // FIXME: This is sketchy. -flibit` It turns out that one of these weren't caught, over at line `471`. `tstring=tstring[tstring.length()-1];` This causes builds compiled on Windows to segfault if you load more than one level in the editor. I added a quick `if` around it, setting `tstring` to an empty string, which seems to fix the problem.
This commit is contained in:
parent
e3025a6b27
commit
ca0bfcfa80
1 changed files with 5 additions and 1 deletions
|
@ -468,7 +468,11 @@ void editorclass::removehookfromscript(std::string t)
|
|||
{
|
||||
//If this line is not the start of a new hook, remove it!
|
||||
tstring=script.customscript[i];
|
||||
tstring=tstring[tstring.length()-1];
|
||||
if (tstring.length() > 0) {
|
||||
tstring=tstring[tstring.length()-1];
|
||||
} else {
|
||||
tstring="";
|
||||
}
|
||||
if(tstring==":")
|
||||
{
|
||||
//this is a hook
|
||||
|
|
Loading…
Reference in a new issue