1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-18 10:38:31 +02: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:
AllyTally 2020-02-08 00:10:45 -04:00 committed by Ethan Lee
parent e3025a6b27
commit ca0bfcfa80

View File

@ -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