Fix possible game crash when using invalid coordinates in !bubble

Point arguments are supposed to look like "x,y", but if you gave it anything after y, it would crash. The comma split data is stored by reference, but the String it was referencing goes out of scope and is potentially destructed. Fix it by expliticly keeping a String object in scope until we're done.
This commit is contained in:
jacob1 2025-02-12 23:07:01 -05:00
parent a153b614ea
commit bca4d66ace
No known key found for this signature in database
GPG Key ID: 4E58A32D510E1995

View File

@ -53,18 +53,21 @@ AnyType::operator StringType()
AnyType::operator PointType()
{
if(type == TypePoint)
if (type == TypePoint)
{
return PointType(std::get<ui::Point>(value));
}
else if(type == TypeString)
else if (type == TypeString)
{
int x, y;
if(String::Split comma = std::get<String>(value).SplitNumber(x))
if(comma.After().BeginsWith(","))
if(String::Split end = comma.After().Substr(1).SplitNumber(y))
if(!end.After().size())
if (String::Split comma = std::get<String>(value).SplitNumber(x))
if (comma.After().BeginsWith(","))
{
String after = comma.After().Substr(1);
if (String::Split end = after.SplitNumber(y))
if (!end.After().size())
return PointType(x, y);
}
throw InvalidConversionException(type, TypePoint);
}
else